【问题标题】:ggplot histogram color gradientggplot 直方图 颜色渐变
【发布时间】:2019-08-22 02:13:07
【问题描述】:

我正在尝试在直方图中可视化来自 ggplot2 的钻石数据,其中显示了克拉的分布。

我尝试将 aes 值从 ggplot 移动到 geom_histogram(),尝试 ..fill..,并以不同的方式操作代码,但结果是相同的。

histogram<- ggplot(diamonds, aes(x=carat, fill=carat)) +
  geom_histogram(binwidth = 0.1) + scale_fill_gradient(low='blue', high='yellow')

我希望看到我的直方图随着克拉的增加而从蓝色变为黄色,但我仍然看到它是灰色的。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    试试fill=..x..:

    ggplot(diamonds, aes(x=carat, fill=..x..)) +
      geom_histogram(binwidth = 0.1) + scale_fill_gradient(low='blue', high='yellow')
    

    【讨论】:

    • 谢谢!我想我对阅读的文档和其他问题感到困惑,所以当我看到 ..x.. 时,我想我需要用我的 x 替换 x。
    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-10
    • 2022-01-17
    • 1970-01-01
    • 2020-11-27
    • 2017-03-10
    相关资源
    最近更新 更多