Home > OS >  Overriding Colors in Ggplot2
Overriding Colors in Ggplot2

Time:03-28

I made the following graph in R (from: enter image description here

  • Is it possible to change the "yellow" color to "red"?

Normally, I would have changed the colors like this (p9

Full Code:

stat_colors=c("#7FC97F", "#BEAED4", "#FDC086", "red", "#386CB0")
names(stat_colors) =  c("Mean = 0.04, Standard Deviation = 0.01",
                        "Mean = 0.2, Standard Deviation = 0.08",
                        "Mean = 0.3, Standard Deviation = 0.05",
                        "Mean = 0.5, Standard Deviation = 0.06",
                        "Mean = 0.7, Standard Deviation = 0.07"
)

p9 <- ggplot(data.frame(x = c(0, 1)), aes(x = x))  
  
  stat_function(fun = dnorm, args = list(0.2, 0.08),
                aes(colour = "Mean = 0.2, Standard Deviation = 0.08"), size = 1.5)  
  
  stat_function(fun = dnorm, args = list(0.4, 0.1),
                aes(colour = "Mean = 0.04, Standard Deviation = 0.01"), size = 1.5)  
  
  stat_function(fun = dnorm, args = list(0.3, 0.05),
                aes(colour = "Mean = 0.3, Standard Deviation = 0.05"), size = 1.5)  
  
  stat_function(fun = dnorm, args = list(0.7, 0.07),
                aes(colour = "Mean = 0.7, Standard Deviation = 0.07"), size = 1.5)   
  
  stat_function(fun = dnorm, args = list(0.5, 0.06),
                aes(colour = "Mean = 0.5, Standard Deviation = 0.06"), size = 1.5)  
  
  scale_x_continuous(name = "Probability",
                     breaks = seq(0, 1, 0.2),
                     limits=c(0, 1))  
  scale_y_continuous(name = "Frequency")  
  scale_color_manual(values= stat_colors)  
  ggtitle("Normal function curves of probabilities")  
  #scale_colour_brewer(palette="Accent")  
  labs(colour = "Groups")  
  theme_bw()  
  theme(axis.line = element_line(size=1, colour = "black"),
        panel.grid.major = element_line(colour = "#d3d3d3"),
        panel.grid.minor = element_blank(),
        panel.border = element_blank(), panel.background = element_blank(),
        plot.title = element_text(size = 14, family = "Tahoma", face = "bold"),
        text=element_text(family="Tahoma"),
        axis.text.x=element_text(colour="black", size = 9),
        axis.text.y=element_text(colour="black", size = 9))
p9
  • Related