从ggplot2中删除顶部和右侧边框

5

能否从ggplot2图形中去除顶部和右侧边框?

也就是说,我想保留x轴和y轴,但要删除围绕图形的其余黑色框架。

//M

2个回答

2
您可以将此添加到您的图表中。
+ opts(panel.grid.minor = theme_blank()) 
+ opts(panel.grid.major = theme_blank()) 
+ opts(axis.line = theme_segment())

自从0.9.2版本以来,opts已被theme所替代:
+ theme(panel.grid.minor = element_blank()) 
+ theme(panel.grid.major = element_blank()) 
+ theme(axis.line = element_segment())

我有以下函数:theme_white<-function(){theme_update(panel.background=theme_blank(),panel.grid.major=theme_blank(),panel.grid.minor=theme_blank())} 我添加了axis.line=theme_segment(),但仍然留下黑色边框...我也尝试了opts的方法,但无济于事... - Misha
也许尝试将panel.border = theme_blank()设置为清除绘图周围的所有边框。 - Sarah West
你能上传一张图片,这样我或许可以看到哪里出了错误吗? - Sarah West
2
终于找到了...panel.background=theme.rect(colour=NA) - Misha

2

1
辅助函数的原始代码已经无法工作(我想是因为更新了ggplot),但Rudolf Cardinal发布了这个有效的更新:http://egret.psychol.cam.ac.uk/statistics/R/extensions/rnc_ggplot2_border_themes_2013_01.r - Alex Holcombe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接