gpt4 book ai didi

r - 在ggplot2中轻松地将 '(all)' facet添加到facet_wrap?

转载 作者:行者123 更新时间:2023-12-04 06:03:47 24 4
gpt4 key购买 nike

我在 facet_wrap documentation 中有看起来像这个例子的数据:


(来源:ggplot2.org)

我想用整体 View 填充最后一个方面,使用所有数据。

是否有一种简单的方法可以使用 facet_wrap 添加“总”方面? ?为 facet_grid 添加边距很容易,但该选项在 facet_wrap 中不存在.

注意:使用 facet_grid如果您想要上图中的象限,则不是一个选项,这需要 ncolnrow来自 facet_wrap 的参数.

最佳答案

library(ggplot2)

p <- qplot(displ, hwy, data = transform(mpg, cyl = as.character(cyl)))
cyl6 <- subset(mpg, cyl == 6)
p + geom_point(data = transform(cyl6, cyl = "7"), colour = "red") +
geom_point(data = transform(mpg, cyl = "all"), colour = "blue") +
facet_wrap(~ cyl)

enter image description here

关于r - 在ggplot2中轻松地将 '(all)' facet添加到facet_wrap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18933575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com