Changing font size and direction of axes text in ggplot2
Solution 1:
Use theme()
:
d <- data.frame(x=gl(10, 1, 10, labels=paste("long text label ", letters[1:10])), y=rnorm(10))
ggplot(d, aes(x=x, y=y)) + geom_point() +
theme(text = element_text(size=20),
axis.text.x = element_text(angle=90, hjust=1))
#vjust adjust the vertical justification of the labels, which is often useful
There's lots of good information about how to format your ggplots here. You can see a full list of parameters you can modify (basically, all of them) using ?theme
.
Solution 2:
Ditto @Drew Steen on the use of theme()
. Here are common theme attributes for axis text and titles.
ggplot(mtcars, aes(x = factor(cyl), y = mpg))+
geom_point()+
theme(axis.text.x = element_text(color = "grey20", size = 20, angle = 90, hjust = .5, vjust = .5, face = "plain"),
axis.text.y = element_text(color = "grey20", size = 12, angle = 0, hjust = 1, vjust = 0, face = "plain"),
axis.title.x = element_text(color = "grey20", size = 12, angle = 0, hjust = .5, vjust = 0, face = "plain"),
axis.title.y = element_text(color = "grey20", size = 12, angle = 90, hjust = .5, vjust = .5, face = "plain"))