r - 用 ggplot 填充直方图 - 改变颜色

标签 r ggplot2 graph histogram fill

我正在学习如何使用 R 和 ggplot 库,但遇到了更改以下直方图颜色的挑战!我确实设法改变了图中的全色,但它是纯色的!我想用不同的颜色进行计数,但不知何故我无法找到正确的方法!你能帮我把它换成另一种颜色吗?

df4 <- data.frame(rnorm(10000,100,10))
colnames(df4) <- c("Value")

histi_base2 <- ggplot(df4, aes(x=Value))

histi5 <- histi_base2 + geom_histogram(binwidth = 1, colour="blue", alpha=0.8, aes(fill=..count..)) + labs(title="My first Histogram", subtitle = "in blue")
histi5

Blue Histogram

最佳答案

你可以使用scale_fill_gradient:

df4 <- data.frame(rnorm(10000,100,10))
colnames(df4) <- c("Value")

library(ggplot2)

ggplot(df4, aes(x=Value)) + 
  geom_histogram(binwidth = 1, alpha=0.8, aes(fill=..count..)) + 
  scale_fill_gradient(low = "red", high = "green") +
  labs(title="My first Histogram")

enter image description here

关于r - 用 ggplot 填充直方图 - 改变颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70339544/

相关文章:

linux - 从 munin 数据中删除单个样本

java - 迭代减少到空矩阵

R 绘图使用 ggplot facet_grid 添加图例

r - 如何从R中的矩阵中写出?

r - 使用 geom_dotplot 时绘图区域被截断

r - 如何从ggplot2中的特定geom更改大小?

r - 如何使用 knit 将环境传递给 Rcpp block ?

r - 从频率表生成 data.frame

r - 自动克里格空间数据

javascript - C3.js,y轴时间