r - How to align rotated multi-line x axis text in ggplot2? -
here example of have:
x <- head(mtcars) x$rn <- rownames(x) x$rn[5] <- 'hornet\nsportabout' library(ggplot2) ggplot(x, aes(x = rn, y = mpg)) + geom_point() + theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) ggsave('test.png', width = 3, height = 3) as can see, 'hornet\nsportabout' close next 1 , move little bit left. expected x-axis text looks one:
i thought should set vjust = 0.5, move axis text down. tried severial combinations of vjust , hjust , still can not desired output. there way axis.text aligned shown in second plot (manually created libreoffice draw) ggplot2?
this plot exported default width , height rstudio.
picture exported default values
also can same using package grdevices. code this:
library(grdevices) png("test1.png",width = 592, height = 379, units = "px") ggplot(ggplot(x, aes(x = rn, y = mpg)) + geom_point() + theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) dev.off() now 1 can see file test1.png in current working directory.
wiki


Comments
Post a Comment