gpt4 book ai didi

r - 在ggplot中设置颜色手册

转载 作者:行者123 更新时间:2023-12-04 10:12:52 25 4
gpt4 key购买 nike

我正在尝试获得不同的颜色a) -inf 为 1(不包括 1)b) 1(不包括 1)至 infc) 然后是值为 1 的值我知道如何获取 a) 和 b) ,但不知道如何获取 c)..

这是我的

scale_color_manual(name = "df",
values = c("(-Inf,1]" = "red",
# "1" = "yellow", #doesnt work
"(1, Inf]" = "green"))

最佳答案

如果数据是 COLOR,则将数据分组(组 == 1) , < 1> 1 .并由该组指定美学中的颜色。
scale_color_manual 中指定想要的颜色.

d <- data.frame(x = sample(c(Inf, -Inf, 1), 100, replace = TRUE),
y = rnorm(100))
d$COLOR <- "One"
d[d$x < 1, ]$COLOR <- "-INF"
d[d$x > 1, ]$COLOR <- "+INF"

library(ggplot2)
ggplot(d, aes(x, y, color = COLOR)) +
geom_point() +
scale_color_manual(name = "My colors",
values = c("red", "green", "yellow"))

enter image description here

关于r - 在ggplot中设置颜色手册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46529364/

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