Emiliano
Emiliano

Reputation: 13

How to set custom colors in ggplot2 using theme_classic function

I am making a ggplot that shows the probability (from 0 to 1) of 10 species occurring in relation to the percentage of a variable ¨x¨ (6.15% to 99.22%).

I am using the function ggplot and the arguments geom_line and theme_classic (code bellow) and I am happy with the plot overall because I can manually change from a standardized values to the real values as the breaks and labels (sorry if the code is too messy), but the colours for each species are too similar, they get easily confused.

Is there a way to manually select them while using theme_classic? Is there a simple hack/way to change the colors to others more distinct?

Plot: [1]: https://i.sstatic.net/k5st4.jpg

Thanks!

ggplot(data=data.table,
   aes(x=percentage.x, y=probability, colour=Species)) + 
geom_line()+ 
theme_classic() + 
xlab("Percentage") + ylab(expression("Probab[enter image description here][1]ility")) +
scale_y_continuous(limits=c(0,1), breaks = seq(0,1, by=.25)) +
scale_x_continuous(
breaks = c( -6.83305, -5.04805, -3.263056, -1.47805, 0.306943954),
label = c(sprintf("%0.2f",((-6.83305*
(realvalue$standard.deviation))+realvalue$average)*100),
          sprintf("%0.2f",((-5.04805*
(realvalue$standard.deviation))+realvalue$average)*100),
          sprintf("%0.2f",((-3.263056*
(realvalue$standard.deviation))+realvalue$average)*100),
          sprintf("%0.2f",((-1.47805*(realvalue$standard.deviation))+realvalue$average)*100),
          sprintf("%0.2f",((0.306943954*(noestandar$desviacion.porcentaje.selva))+noestandar$media.porcentaje.selva)*100)))

Upvotes: 1

Views: 1069

Answers (2)

M.Viking
M.Viking

Reputation: 5398

I think this will work:

... +
scale_colour_brewer(palette = "Set3")

ColorBrewer palette "Set3" is a distinct set of more than 10 colors. "Paired" might look good too.

https://www.rdocumentation.org/packages/ggplot2/versions/3.3.3/topics/scale_colour_brewer

enter image description here

Upvotes: 1

NHermans
NHermans

Reputation: 56

Or something like:

   + scale_colour_manual(values = c("black","blue"))

Upvotes: 2

Related Questions