ggplot2的geom_bar()未显示默认的x轴刻度

时间:2020-06-28 15:17:06

标签: r ggplot2 geom-bar

作为一个简单的示例,我将使用菱形数据:

data(diamonds)

ggplot(diamonds, aes(x = clarity, y = carat, fill = cut)) +
  geom_bar(stat = "identity")

这将为我提供以下输出,其中未标注x轴:

missing x- and y-axis labels

如何显示x和y轴的值?我一直在搜寻,而且还没有找到解决方法...

对于我的真实数据集,我的x轴值是离散的,并且使用scale_x_discrete()不会更改结果。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

您的代码工作正常,我相信您必须更新ggplot2并开始一个新的R会话:

data(diamonds)

ggplot(diamonds, aes(x = clarity, y = carat, fill = cut)) +
  geom_bar(stat = "identity")

enter image description here

相关问题