1

I would like to change the colour of the confidence bands of two data sets in a common scatter plot. The colour of the data set have been already changed from the default to costumized. Now, the colours of the confidence bands shall be changed to blue and green as well.

The data set looks like this.

I would appreciate your suggestions. Thanks!

Stage OAL TL Blasto 57 95 Blasto 61 85 ... Oozoid 7 9 Oozoid 22 29 ...

library("ggplot2")
library("reshape2")
library("tidyverse")

p<-ggplot(ThomTOAL,aes(x=TL,y=OAL,colour=Stage))+
  geom_point(alpha=0.4,size=2.5)+
  geom_smooth(method=lm)+
  labs(x="\nTL (mm)",y="OAL (mm)\n")+
  scale_color_manual(values=c('blue','green'))+
  theme(axis.title.x=element_text(size=18),
        axis.text.x=element_text(size=14,colour="black"),
        axis.title.y=element_text(size=18),
        axis.text.y=element_text(size=14,colour="black"),
        axis.ticks=element_blank(),
        legend.position=c(0.18,0.87),
        legend.text=element_text(colour="black",size=14),
        legend.title=element_blank())
p
OceanSun3
  • 31
  • 4
  • 1
    Confidence band color is achieved by `fill`, so you'll likely want to add that as an aesthetic. – aosmith Nov 27 '19 at 18:24
  • You are right that with `fill` I can add a colour to the confidence bands, but how do I modify them according to my chosen colours? – OceanSun3 Nov 27 '19 at 18:54
  • `scale_fill_manual()`. :) – aosmith Nov 27 '19 at 19:08
  • I added `scale_fill_manual(values=c("blue","green"))+`after the `scale_color_manual` command, but it still didn't change the colour? – OceanSun3 Nov 27 '19 at 19:30
  • 1
    Help us help you be adding a reproducible example. There's some good info on adding an example [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Using `scale_fill_manual(values = ...)` in addition to `scale_color_manual(values = ...)` after mapping a variable to both `fill` and `color` is the general way to control fill and color colors, so I'm guessing something else is going on with your code or dataset. – aosmith Nov 27 '19 at 19:38

1 Answers1

1

If I understood you correctly, you're looking for color = and fill = inside the geom_smooth() argument/method.

I used mtcars dataset for reproducibility.

library(tidyverse)

mtcars %>% 
  ggplot(aes(mpg, qsec, group = am, color = am)) + 
  geom_point() + 
  geom_smooth(method = "lm",
              color = "blue", 
              fill = "green")

enter image description here

You can find here more information about it.

DJV
  • 4,743
  • 3
  • 19
  • 34