Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different colors or shades for geom_point and geom_smooth on ggplot for multiple groups

Tags:

r

ggplot2

data1 <- data.frame(x = 1:15,    # Create example data frame
                   y = c(runif(15, 0, 2),
                         runif(15, 2, 6),
                         runif(15, 3, 4),
                         runif(15, 1, 3)),
                   group = rep(LETTERS[1:4], each = 15))

ggplot(data1, aes(x,y, color=group))+
  geom_point() +
geom_smooth(se=FALSE)

enter image description here

I have the following plot, and I would like to make the colors of the geom_smoth be slightly different than points (I.e. darker shade), I can't figure out how I can do it

like image 677
yuliaUU Avatar asked Oct 15 '25 23:10

yuliaUU


1 Answers

Thanks @r2evans and @TarJae!

ggplot(data1, aes(x, y, group = group)) +
 geom_point(aes(color=group)) +
  scale_color_manual(values = c("grey70", "red", "green", "steelblue"))+
  ggnewscale::new_scale_color() +
  geom_smooth(aes(color=group),se = FALSE) +
  scale_color_manual(values = c("grey20", "darkred", "darkgreen", "blue"))

enter image description here

like image 144
yuliaUU Avatar answered Oct 17 '25 13:10

yuliaUU