Changing font size and direction of axes text in ggplot2

前端 未结 7 1260
萌比男神i
萌比男神i 2020-11-28 17:37

I am plotting a graph with a categorical variable on the x axis and a numerical variable on the y axis.

For the x axis, given that there are many data points, the de

7条回答
  •  忘掉有多难
    2020-11-28 18:15

    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
    

    enter image description here

    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.

提交回复
热议问题