【问题标题】:How to "un-squish" tick-mark labels on a ggplot?如何在 ggplot 上“取消挤压”刻度线标签?
【发布时间】:2020-06-11 04:57:45
【问题描述】:

我的种族/民族数据编码为 1-7,在我的 ggplot 条形图中,我用正确的名称重新命名了刻度线。

但是,它们被严重挤压在一起,无法读取。谁能告诉我要添加什么或如何调整我的代码以使标签的输入更小或间隔更好并且可以阅读?

非常感谢!

ggplot(my.data, aes(x = c_RaceEth), na.rm = TRUE) + 
  geom_bar(color = "#56B4E9", fill = "#000333") +
  ggtitle("Distribution of Race/Ethnicity") +
  labs(y= "Count", x = "Race/Ethnicity") +
  scale_x_discrete(breaks=c("1","2", "3", "4",  "5", "6", "7"),
        labels=c("Asian or Asian Indian", "Black or African American", "Hispanic, Latino or Spanish", "American Indian or Alaska Native", "Other", "White", "Middle Eastern or North African"))

【问题讨论】:

    标签: r ggplot2 tidyverse


    【解决方案1】:

    在最新版本的 ggplot2 (3.3.0) 中,有一个新功能可以让您完全满足您的需求:scale_x_discrete(guide = guide_axis(n.dodge = 2))。另请参阅here

    library(ggplot2)
    ggplot(mpg) +
      geom_bar(aes(x = manufacturer)) + 
      theme(axis.text.x = element_text(size = 11)) +
      scale_x_discrete(guide = guide_axis(n.dodge = 2))
    

    由reprex package (v0.3.0) 于 2020-06-11 创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-14
      • 2015-08-11
      • 1970-01-01
      • 2021-12-07
      • 2021-04-01
      • 2015-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多