【问题标题】:how do you specify the x axis in ggplot2 histogram?如何在 ggplot2 直方图中指定 x 轴?
【发布时间】:2022-01-20 12:54:28
【问题描述】:

我有以下代码使用 ggplot2 绘制直方图。

ggplot(data = plot, aes(x = total_Amg))+
  geom_histogram(binwidth = 1, colour = "black", fill = "white") +
  facet_wrap(~ gentamicin) 

如何指定在结果图的 x 轴上显示哪些数字,即显示 0 到 8,而不是显示自动生成的数字(见下文)?

【问题讨论】:

标签: r ggplot2


【解决方案1】:

尝试添加:

+ scale_x_continuous(breaks = 0:8, labels = 0:8)

【讨论】:

    【解决方案2】:

    +scale_x_continuous(breaks=0:8) 应该可以解决问题

    【讨论】:

    • 谢谢。我已经尝试过了,对于一个数据集这是可行的,但对于另一个数据集它只显示 0 到 5?我想为这两个图表显示 0 到 8。
    猜你喜欢
    • 1970-01-01
    • 2022-11-22
    • 2021-10-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    相关资源
    最近更新 更多