如何在ggplot2中使用透明背景

您所在的位置:网站首页 excel柱状图背景透明 如何在ggplot2中使用透明背景

如何在ggplot2中使用透明背景

2024-07-13 08:11| 来源: 网络整理| 查看: 265

如何在ggplot2中使用透明背景经过 本杰明·安德森博 7月 24, 2023 指导 0 条评论

您可以使用以下语法在 ggplot2 的绘图中创建透明背景:

p+ theme( panel. background = element_rect(fill=' transparent '), #transparent panel bg plot. background = element_rect(fill=' transparent ', color= NA ), #transparent plot bg panel. grid . major = element_blank(), #remove major gridlines panel. grid . minor = element_blank(), #remove minor gridlines legend. background = element_rect(fill=' transparent '), #transparent legend bg legend. box . background = element_rect(fill=' transparent ') #transparent legend panel )

如果您决定使用ggsave()导出绘图,请务必指定背景应该是透明的:

ggsave(' myplot.png ' , p, bg = ' transparent ' )

以下示例展示了如何在实践中使用此语法。

示例:在 ggplot2 中使用透明背景

以下代码展示了如何在 ggplot2 中创建简单的分组箱线图:

library (ggplot2) #make this example reproducible set. seeds (1) #create dataset data


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3