0

I'm trying to change the default panel background colour in the ggplot2 package install on my computer. The current default is 'grey90', and I want to change it to '#E8EDFB'.

I tried to do this by changing the default theme ggplot2 uses, theme_grey.

Using either

fixInNamespace("theme_grey", pos="package:ggplot2")

or

fixInNamespace("theme_grey", ns="ggplot2")

as suggested here, gives me a nice editor where I can change the relevant bit of code:

panel.background =   element_rect(fill = "grey90", colour = NA)

I changed "grey90" to '#E8EDFB' and saved. Whenever I re-run one of the commands above, I now again get the editor which indeed shows my edited code instead of the original. However, when I run theme_grey, I just get the original code outputed to my console, not my changed code, and the panel backgrounds on my plots are also still grey.

How do I get my plot panel backgrounds to default to #E8EDFB instead of grey?

NOTE: I want to change the default permanently, not just change the color for one plot or for the session.

Community
  • 1
  • 1
Marleen
  • 45
  • 1
  • 7

1 Answers1

3
theme_set(theme_grey() + theme(panel.background = element_rect(fill="red")))
baptiste
  • 75,767
  • 19
  • 198
  • 294
  • thanks, but this doesn't give me exactly what I want: when I ran your code and then created a plot, the panel background was indeed red, but when I closed the session and restarted R my panel backgrounds were back grey. I'm hoping to change the default permanently. – Marleen Nov 05 '14 at 13:52
  • 1
    if you want something permanent, you can either i) place the above in your .Rprofile; ii) fork+edit the ggplot2 package before installing it. For consistency with other people using my code, I prefer to just put this one line at the top of my scripts though. – baptiste Nov 05 '14 at 13:55