r - Rotate switched facet labels in ggplot2 facet_grid -


i plot barplots on top of each other using facet_grid:

library(ggplot2)  df <- group_by(mpg, manufacturer) %>%   summarise(cty = mean(cty), hwy = mean(hwy)) %>%   ungroup()  df <- melt(df, id.vars = "manufacturer")  ggplot() +   geom_bar(data =df, aes(x = variable, y = value), stat = "identity") +   facet_grid(manufacturer ~ ., switch = "y") 

i use switchargument of ggplot2::facet_grid()to let facet labels displayed on y-axis instead of on top of each facet. problem facet labels plotted vertically , therefore cropped. there way plot facet -labels horizontally? questions found far related rotating x-axis labels only, not facet labels.

you need add theme() , specify angle in strip.text.y

library(ggplot2) df <- group_by(mpg, manufacturer) %>%   summarise(cty = mean(cty), hwy = mean(hwy)) %>%   ungroup()  df <- melt(df, id.vars = "manufacturer")  ggplot() +   geom_bar(data =df, aes(x = variable, y = value), stat = "identity") +   facet_grid(manufacturer ~ ., switch = "y")+  theme(strip.text.y = element_text(angle = 180)) 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -