如何将颜色参数从产生渐变颜色更改为不同的颜色?
How can I change the colour argument from producing gradient colors to distinct colors?
正在复制我的部分数据:
tibble(x=c(3.98, 3.98, 3.98, 3.98, 3.90, 3.90, 3.90, 3.90, 3.85, 3.85, 3.85, 3.85), y = c(-70.1, -63.65, -63.65, -63.65, -61.40, -59.12, -59.12, -59.12, -65.01, -58.90, -58.90, -58.90), type = c("obs", "true", "true", "true", "obs", "true", "true", "true", "obs", "true", "true", "true"), s = c(1, 1, 2, 3, 2, 1, 2, 3, 3, 1, 2, 3))
使用上述数据,我想生成如下所示的图:Target plot
我提供的数据只是部分数据,所以输出可能会有所不同。
我已经使用下面的代码成功获得了我想要的方式:
d <- read_csv("data/data.csv")
d %>%
filter(type == 'true') %>%
ggplot(aes(x,y)) +
geom_line() +
geom_point(data = d %>% filter(type == 'obs'), aes(colour = s)) +
facet_wrap(~s)
问题是我得到这样的情节:Result
如何让 3 组具有 3 种不同的颜色(如目标图中所示)而不是具有蓝色渐变(如结果所示)?
将 s
值更改为 geom_point
中的 factor
。
library(dplyr)
library(ggplot2)
d %>%
filter(type == 'true') %>%
ggplot(aes(x,y)) +
geom_line() +
geom_point(data = d %>% filter(type == 'obs'), aes(colour = factor(s))) +
facet_wrap(~s)
正在复制我的部分数据:
tibble(x=c(3.98, 3.98, 3.98, 3.98, 3.90, 3.90, 3.90, 3.90, 3.85, 3.85, 3.85, 3.85), y = c(-70.1, -63.65, -63.65, -63.65, -61.40, -59.12, -59.12, -59.12, -65.01, -58.90, -58.90, -58.90), type = c("obs", "true", "true", "true", "obs", "true", "true", "true", "obs", "true", "true", "true"), s = c(1, 1, 2, 3, 2, 1, 2, 3, 3, 1, 2, 3))
使用上述数据,我想生成如下所示的图:Target plot
我提供的数据只是部分数据,所以输出可能会有所不同。
我已经使用下面的代码成功获得了我想要的方式:
d <- read_csv("data/data.csv")
d %>%
filter(type == 'true') %>%
ggplot(aes(x,y)) +
geom_line() +
geom_point(data = d %>% filter(type == 'obs'), aes(colour = s)) +
facet_wrap(~s)
问题是我得到这样的情节:Result
如何让 3 组具有 3 种不同的颜色(如目标图中所示)而不是具有蓝色渐变(如结果所示)?
将 s
值更改为 geom_point
中的 factor
。
library(dplyr)
library(ggplot2)
d %>%
filter(type == 'true') %>%
ggplot(aes(x,y)) +
geom_line() +
geom_point(data = d %>% filter(type == 'obs'), aes(colour = factor(s))) +
facet_wrap(~s)