网格线和背景的颜色

发布于 2024-11-08 23:15:44 字数 451 浏览 1 评论 0原文

看来这个问题首先出现< /a> 大约在 2007 年。

问题是这样的:

在 R 中使用 ggplot2 绘图时如何更改网格线和背景颜色?我添加两张图片作为背景和网格线颜色含义的示例。

早在 2007 年,Hadley Wickham 就表示缺少外观功能(包括更改背景颜色)。有谁知道是否有允许更改背景颜色和网格线颜色的更新?

提前致谢

before 在此处输入图像描述

It seems that this question first appeared around 2007.

The question is this:

How to change the gridline and background color when plotting with ggplot2 in R? I add two pictures as an example of what I mean by background and gridline color.

Back in 2007, Hadley Wickham said that appearance functionalities were missing (this included changing the color of the background). Does anybody know if there's an update that allows changing the background color and the color of the gridlines?

Thanks in advance

before
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当爱已成负担 2024-11-15 23:15:44

注意:从0.9.2版本开始,这是使用完成的theme

theme(panel.background = element_rect(colour = "white"))

此外,还有panel.grid.majorpanel.grid.minor选项。有关选项的完整列表和一些示例,请参阅此处?theme 处也有文档。

在旧版本的ggplot2中,这是通过以下方式完成的:

opts(panel.background=theme_rect(colour="white"),...)

您还可以使用theme_bw()切换到更传统的主题。

您还可以在 this SO 线程上找到有关主题和 opts() 的信息。

Note: Since version 0.9.2 this is done using theme:

theme(panel.background = element_rect(colour = "white"))

Additionally, there are panel.grid.major and panel.grid.minor options. See here for a full list of options and some examples. There is also documentation at ?theme.

In older version of ggplot2 this was done via:

opts(panel.background=theme_rect(colour="white"),...)

You can also switch to more traditional theme using theme_bw().

You can also find information on themes and opts() on this SO thread.

稀香 2024-11-15 23:15:44

我发现一个有点隐藏的选项有助于识别这些东西的“位置”以及它们的名称:

theme_get()

它向您显示所有主题选项的调用和定义。另外,如果您打算搞乱主题,您应该记住,您可以将许多调用保存为列表对象...例如:

plotoptions <- list(opts(x,y,z),scale_fill_manual(...),labs(x,y,z))
someplot + plotoptions

当我自定义主题以匹配时,我经常使用它企业风格或类似的东西。

A somewhat hidden option that I find helpful for identifying "where" these things are and what they are called is:

theme_get()

It shows you both the call and the definitions for all of the theme options. Also, if you're going to be messing about with thematics, you should keep in mind that you can save a number of calls as a list object... for example:

plotoptions <- list(opts(x,y,z),scale_fill_manual(...),labs(x,y,z))
someplot + plotoptions

I use this a lot when I'm customizing themes to match a corporate style or something of that like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文