Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plots in ggplot2 appearing without grey background

Tags:

r

ggplot2

I just used ggplot2 earlier and all my plots are appearing without the grey default background. I am not sure why its doing that because it was working two weeks ago and I have not touched R since then. Not sure if its a bug in R or on my part.

library(ggplot2)
library(gridExtra)
library(cowplot)
p1=ggplot(health,aes(Smoker,Pulse))+geom_boxplot(aes(fill=factor(Smoker)))   +geom_jitter()
p1

enter image description here

Before I use to get the background with the grey tiles and this what I am getting above. Any help would be great thanks.

like image 531
user60887 Avatar asked Dec 14 '22 07:12

user60887


1 Answers

Loading cowplot changes the default layout of ggplot2. Check out the cowplot introduction:

I prefer a clean and sparse layout for publication. I also prefer the approach of building a graph by adding elements rather than taking them away. Therefore, the default design of cowplot has no grid at all. It looks similar to ggplot2’s theme_classic(), but there are a few important but subtle differences, mostly with respect to font sizes.

PS: adding theme_grey() to your plot should return it to the ggplot2 default

like image 57
bouncyball Avatar answered Dec 21 '22 22:12

bouncyball