如何更改单个facet_wrap面板的格式?
是否可以改变单个方面图的格式?例如,使用下面的示例代码,可以更改 cyl=8 图的标题或背景颜色吗?
library(ggplot2)
ggplot(mtcars, aes(x=gear)) +
geom_bar(aes(y=gear), stat="identity", position="dodge") +
facet_wrap(~cyl)
Is it possible to alter the format of an individual facet plot? For example, using the sample code below, can one change the color of the title or background for the cyl=8 plot?
library(ggplot2)
ggplot(mtcars, aes(x=gear)) +
geom_bar(aes(y=gear), stat="identity", position="dodge") +
facet_wrap(~cyl)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以修改 ggplot2 grobs,例如:
更新:这应该适用于 ggplot2 0.9.3
You can modify the ggplot2 grobs, for instance:
Update: This should work with ggplot2 0.9.3
我知道这是一个老问题,所以原始海报可能早已消失,但我仍然认为它值得回答,作为未来搜索者的资源。 rcs 接受的答案确实有效,但我发现它相当不稳定且很糟糕。最后我决定采取更温和但更稳定的方法。使用这种方法,您只能更改背景,但这足以满足我的目的,也可能适合其他人,我的方法是使用
geom_rect
重新着色背景,如下所示:I know this is an old question so the original poster is probably long gone but I still think it is worth answering as a resource to future searchers. The accepted answer from rcs does work, but I found it to be rather unstable and hacky. In the end I decided that a more modest but more stable approach is in order. With this method you can only change the background but that suffices for my purposes and might for others, my approach is to use
geom_rect
to recolour the background, like so:这可能会帮助您更接近您想要的:
This might help you get a little bit closer to what you want: