r - 如何从ggtheme中删除框架

标签 r ggplot2

我正在使用 ggplot 绘制一些数据。另外,我使用 ggthemes 包中的 gdocs 主题。

library(ggthemes)
data <- data.frame(x = 1:10, y = 1:10)
g <- ggplot(data, aes (x = x, y = y)) + geom_point()
g + theme_gdocs()

gdocs theme

我想使用这个主题,但没有围绕整个图的边框,类似于默认主题。

g

default theme

我应该修改哪些设置才能实现此目的?

这是我第一次在 ggplot 中使用其他主题,所以我可能会错过一些简单的东西,但我无法让它自己工作。预先感谢您的帮助。

最佳答案

发布上面由 hrbrmstr 提供的解决方案:

在调用theme时使用plot.background=element_blank():

library(ggthemes)
data <- data.frame(x = 1:10, y = 1:10)
g <- ggplot(data, aes (x = x, y = y)) + geom_point()
g + theme_gdocs() + theme(plot.background=element_blank())

来自 ggplot2 docs :

Use theme() to modify individual components of a theme, allowing you to control the appearance of all non-data components of the plot. theme() only affects a single plot: see theme_update() if you want modify the active theme, to affect all subsequent plots.

...

plot.background: background of the entire plot (element_rect; inherits from rect)

这适用于使用ggplot2创建的任何绘图,当然,不仅仅是使用theme_gdocs()创建的绘图。

关于r - 如何从ggtheme中删除框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32923618/

相关文章:

r - 如何让ggplot ecdf以填充背景进行绘图

r - 标准化 ggplot 中覆盖密度图的 x 尺度

在 ggplot 中反转日期时间(POSIXct 数据)轴

r - 减去行并创建新的行名称

r - 有没有人尝试在 Fedora 或 Ubuntu 上运行 Revolutions Enterprise 4?

r - 我可以阻止通过 R 中的 NextMethod 传递参数吗?

r - 无法加载 tidyverse 库

r - 如何将 x 轴标签从使用 coord_polar 的 ggplot 的中心移开?

r - 在月轴上准确放置 geom_text 标签

sql - ODBC 连接,在 R 中获取一个表