首页 > 解决方案 > ggplot2中的多个样条线 - 想要手动控制颜色

问题描述

例子;

library(dplyr)
library(ggplot2)
library(mgcv)

# Summer
Summer <- mgcv::gamSim(eg=5,n=40000,dist="normal",scale=0.6,verbose=TRUE) %>%
  mutate(x = x2 * 20) %>%
  rename("Estação" = x0) %>%
  mutate(Estação = ifelse(Estação == "1", "Inverno", Estação)) %>%
  filter(.,Estação == "Inverno") %>%
  select(y, x, Estação)

# Winter
Winter <- mgcv::gamSim(eg=5,n=50000,dist="normal",scale=1.0,verbose=TRUE) %>%
  mutate(x = x1 * 20) %>%
  rename("Estação" = x0) %>%
  mutate(Estação = ifelse(Estação == "3", "Verão", Estação)) %>%
  filter(.,Estação == "Verão") %>%
  select(y, x, Estação)

# Bind
DF <- rbind(Summer, Winter)


# Plot
Plot <- DF %>%
  ggplot(., aes(x = x, y = y, fill = Estação)) +
  geom_jitter() +
  geom_point(shape=21, alpha = 0.5,  size=0.05) +
  geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs", k = 10),  lwd = 1.6)
Plot

如何手动控制这 2 条样条线的颜色?

我希望它们每个都有不同的颜色,并且比几何点的颜色更暗。

标签: rggplot2colorsspline

解决方案


推荐阅读