0

I have a large number of plots with 2 groups. I want to set the colours to "purple" and "navyblue".
I can obviously add:

p + scale_color_manual(values=c("purple", "navyblue"))

to all my plots.

Is there a way to set these two colours at the beginning of my code with a single line of code, and avoid repeating the scale_color_manual() call for every single plot?

user13424
  • 111
  • 1
  • 4
  • 2
    Check this previous question: https://stackoverflow.com/questions/41717154/how-to-set-themes-globally-for-ggplot2 – mrhellmann Apr 14 '20 at 19:54
  • Nope. Maybe write your own helper function to do that automatically. Or if you keep all your plots in a list, and transform them all at once. But `scales` aren't kept in the theme. – MrFlick Apr 14 '20 at 19:56
  • You can shorten the call slightly by assigning the colors to a variable at the beginning of your code: `colors <- c("purple","navyblue")` and then using `scale_color_manual(values = colors)` – Matt Apr 14 '20 at 19:58
  • conversation [here](https://stackoverflow.com/questions/53750310/how-to-change-default-color-scheme-in-ggplot2) is worth reading – paqmo Apr 14 '20 at 20:03
  • 1
    I wrote a fairly [comprehensive answer](https://stackoverflow.com/questions/60133210/set-a-document-persistent-ggplot2-color-theme/60136879#60136879) on this topic a couple of months back – Allan Cameron Apr 14 '20 at 20:05
  • 1
    @Matt or even `myscale <- scale_color_manual(values = c("purple","navyblue"))` so you can just do `p + myscale` – Allan Cameron Apr 14 '20 at 20:07
  • Thanks for all your feedback but your comments will not solve my problem. If at all possible, I'd like to define the default colours R is using at the top of my program, so that I don't have to use `p + whatever` in every single plot. (whatever being any shortcut to `scale_color_manual`.) – user13424 Apr 14 '20 at 21:29

0 Answers0