Changing font size and direction of axes text in ggplot2

前端 未结 7 1259
萌比男神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:25

    Another way to deal with overlapping labels is using guide = guide_axis(n.dodge = 2).

    library(dplyr)
    library(tibble)
    library(ggplot2)
    
    dt <- mtcars %>% rownames_to_column("name") %>% 
      dplyr::filter(cyl == 4)
    
    # Overlapping labels
    ggplot(dt, aes(x = name, y = mpg)) + geom_point()
    

    ggplot(dt, aes(x = name, y = mpg)) + geom_point() +
      scale_x_discrete(guide = guide_axis(n.dodge = 2))
    

提交回复
热议问题