Ggplot2: change position of strip.text in facet_grid chart

you can set the position of the legend inside the chart area, for example

... + theme(legend.justification=c(1,0), legend.position=c(1,0)) 

Is there a similar simple way to change the position of the strip text (or factor levels in grouped charts)

 library(reshape2); library(ggplot2) sp <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point() + facet_grid(. ~ sex) sp 

enter image description here

( http://www.cookbook-r.com/Graphs/Facets_%28ggplot2%29/ )

in the lattice, I would use something like strip.text = levels (dat $ Y) [panel.number ()] and panel.text (...), but maybe a cleaner way ...

thanks Christof

+5
source share
1 answer

Here is one approach:

 ggplot(tips, aes(x = total_bill, y = tip / total_bill)) + geom_point() + facet_grid(. ~ sex) + geom_text(aes(label = sex), x = Inf, y = Inf, hjust = 1.5, vjust = 1.5) + theme(strip.background = element_blank(), strip.text = element_blank()) 

However, this does not move strip.text , but adds the geom_text element and disables strip.background and strip.text , but I think it achieves the desired result.

Plot

+4
source

Source: https://habr.com/ru/post/1245331/


All Articles