I have a quick question about facet_wrap labels in ggplot2. Below is a simple data frame. One of the variables (the facet variable) is very long. I want to find a simple way to fit all the text in each facet label. I'm sure there must be some kind of wrap text function or multiple line option? I'm hoping for a method that is not too complex or doesn't really require any other packages if possible.I'm still relatively new with R and hoping for a short and elegant answer within ggplot2.
Q1<-c("Dissatisfied","Satisfied","Satisfied","Satisfied","Dissatisfied","Dissatisfied","Satisfied","Satisfied")
Q2<-c("Dissatisfied","Dissatisfied","Satisfied","Dissatisfied","Dissatisfied","Satisfied","Satisfied","Satisfied")
Year<-c("This is a very long variable name This is a very","This is another really long veriable name a really long","THis is a shorter name","Short name","This is also a long variable name again","Short name","Short name","Another kind of long variable name")
Example<-data.frame(Service,Year,Q1,Q2)
ExampleM<-melt(Example,id.vars=c("Service","Year"))
ggplot(ExampleM, aes(x=variable, fill=value)) +
geom_bar(position="dodge")+
facet_grid(~Year)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…