Change background color of R plot
All right, let's say I have the following plot.
df = data.frame(date=c(rep(2008:2013, by=1)),
value=c(303,407,538,696,881,1094))
barplot(df$value, main="TITLE", col="gray", ylab="People", xlab="Years")
How can I change the background to navy blue?
I know this is possible with ggplot2, but not sure if I can do this with base graphics.
Like
par(bg = 'blue')
# Now do plot
One Google search later we've learned that you can set the entire plotting device background color as Owen indicates. If you just want the plotting region altered, you have to do something like what is outlined in that R-Help thread:
plot(df)
rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "gray")
points(df)
The barplot
function has an add
parameter that you'll likely need to use.