黄土更平滑的跨度参数的小平面ggplot
facet ggplot by span argument of loess smoother
我想通过改变跨度参数使黄土更平滑来制作一个单面图(格子样式)。我尝试使用如下的 for 循环,但没有生成任何图。如果我要使用 ggsave 功能,绘图将单独保存。
另外,我想知道是否有更简洁的方法来完成这样的任务?
x <- rep(1:10,4)
y <- 1.2*x + rnorm(40,0,3)
s <- seq(0.2,0.8,0.1)
# plot the series of plots by varying the span parameter
for (s_i in s) {
qplot(x, y, geom = 'c('point','smooth'), span = s_i)
}
如果你明确地 print
情节(并去掉额外的 '
标记),你的方法会很好用:
for (s_i in s) {
print(qplot(x, y, geom = c('point','smooth'), span = s_i))
}
至于其他方法,我建议将所有地块放在一个列表中
changing_span = list()
for (i in seq_along(s)) {
changing_span[[i]] <- qplot(x, y, geom = c('point','smooth'), span = s[i]) +
labs(title = paste("span:", s[i]))
}
然后你可以将它们全部绘制在一起,例如,
library(gridExtra)
do.call(grid.arrange, changing_span)
我想通过改变跨度参数使黄土更平滑来制作一个单面图(格子样式)。我尝试使用如下的 for 循环,但没有生成任何图。如果我要使用 ggsave 功能,绘图将单独保存。
另外,我想知道是否有更简洁的方法来完成这样的任务?
x <- rep(1:10,4)
y <- 1.2*x + rnorm(40,0,3)
s <- seq(0.2,0.8,0.1)
# plot the series of plots by varying the span parameter
for (s_i in s) {
qplot(x, y, geom = 'c('point','smooth'), span = s_i)
}
如果你明确地 print
情节(并去掉额外的 '
标记),你的方法会很好用:
for (s_i in s) {
print(qplot(x, y, geom = c('point','smooth'), span = s_i))
}
至于其他方法,我建议将所有地块放在一个列表中
changing_span = list()
for (i in seq_along(s)) {
changing_span[[i]] <- qplot(x, y, geom = c('point','smooth'), span = s[i]) +
labs(title = paste("span:", s[i]))
}
然后你可以将它们全部绘制在一起,例如,
library(gridExtra)
do.call(grid.arrange, changing_span)