我想在整个 ggplot2 图周围绘制边框,例如在 Base R 图的情况下使用 box("figure") 函数。
看一下下面的例子:
data <- data.frame(x = 1:5,
y = 1:5)
library("ggplot2")
ggplot(data, aes(x, y)) +
geom_point()
Run Code Online (Sandbox Code Playgroud)
我想在该图周围添加边框,如下所示:
我不敢相信这个信息在任何地方都不存在。不幸的是,我找到的只是如何添加面板边框。
如何在整个ggplot2 图周围添加边框?
All*_*ron 14
主题元素plot.background是element_rect,通常颜色为NA。只需将其更改为您喜欢的任何颜色并调整linewidth以控制线宽即可。
ggplot(data, aes(x, y)) +
geom_point() +
theme(plot.background = element_rect(color = "deepskyblue3", linewidth = 3))
Run Code Online (Sandbox Code Playgroud)