gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 01:55:12 25 4
gpt4 key购买 nike

我正在学习如何使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com