更改R图的背景颜色 [英] Change background color of R plot

查看:697
本文介绍了更改R图的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,假设我有以下情节.

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?

我知道ggplot2可以做到这一点,但是不确定我是否可以使用基本图形来做到这一点.

I know this is possible with ggplot2, but not sure if I can do this with base graphics.

推荐答案

一个Google搜索稍后,我们了解到您可以按照Owen的指示设置整个绘图设备的背景颜色.如果只想更改绘图区域,则必须执行R-Help线程中概述的操作:

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)

barplot函数具有您可能需要使用的add参数.

The barplot function has an add parameter that you'll likely need to use.

这篇关于更改R图的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆