0

I have a additional question to R ggplot2 wrap long x-axis labels over multiple rows because of my problem with the

gsub(" ", "\n", levels())

I try to include it in the following R Code:

ggplot(ntry[!is.na(ntry$V138), ], aes(x=V138, group=1)) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count", fill="#008000", width=0.5) +
geom_text(aes(label = gsub("\\.",",",scales::percent(..prop..)), y= ..prop.. ), stat= "count", vjust = -0.5, color="black", fontface= "bold") +
theme(axis.text= (element_text(face="bold", size="9", color="black")), axis.title = (element_text(face="bold", size= "9", color="black")), panel.background = (element_rect(fill="#FFFFFF")), axis.line = (element_line(color="black"))) +
scale_y_continuous(labels=percent) +
xlab(" ") +
ylab("Prozent") +
ggtitle(paste(attr(ntry, "variable.labels")[grep("^V138$", colnames(ntry))]))

My goal is to get the x-axis-labels in multiple rows. I tried every point in my code I could think or imagine of the possibility it would fit. My main point I tried to integrate gsub was in the part of theme(axis.text= (element_text(face behind the third bracket.

It would be fabulous if someone could help me. I do not see the rigth option.

Thank you

R. LadyCat
  • 11
  • 2
  • Sounds like you want the "labels" argument in `scale_x_discrete` if you are trying to change the x axis tick labels. See [this answer](https://stackoverflow.com/a/20123502/2461552) for an example. – aosmith Jun 26 '17 at 15:28
  • thank you very much :) unfortunately, some of the labels are now in false order or disappered.. but it fits better than anything before. Maybe it is caused by the data frame? – R. LadyCat Jun 26 '17 at 15:47
  • after another try and the add of *levels* like in the first article above, it fits. Thank you :) – R. LadyCat Jun 26 '17 at 15:52

0 Answers0