R 为什么geom_smooth()会自动排除某些值?

R 为什么geom_smooth()会自动排除某些值?,r,ggplot2,R,Ggplot2,我制作了一个ggplot2图形,如下所示: ggplot(dat, aes(x=timepoint, y=y, size=Status, shape=Status)) + geom_point(fill="red") + geom_smooth(method=lm, se=FALSE, size=1, linetype="twodash") + facet_grid(Test ~ Batch, scales="free_

我制作了一个ggplot2图形,如下所示:

ggplot(dat, aes(x=timepoint, y=y, size=Status, shape=Status)) + 
            geom_point(fill="red") + 
            geom_smooth(method=lm, se=FALSE, size=1, linetype="twodash") +
            facet_grid(Test ~ Batch, scales="free_y")
它给出了:

我的代码中还有其他选项来控制图例外观等,但我没有要求
geom_smooth()
排除某些值,正如您所看到的,它会自动排除状态为“FAIL”的点

您可以使用以下数据帧生成这样的绘图,而不使用其他选项(但显示相同的问题):

dat <- structure(list(Test = structure(c(2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("PH", 
"ANTIGENIC ACTIVITY BY ELISA", "WATER CONTENT BY µKARL FISCHER"
), class = "factor"), Batch = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("HB07", 
"HB08"), class = "factor"), timepoint = c(0, 1, 2, 3, 0, 1, 2, 
3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3), Status = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), .Label = c("PASS", "FAIL"), class = "factor"), y = c(11.7, 
12.7, 12.8, 17.6, 8.6, 9.6, 16.5, 15.4, 10.1, 9, 11.7, 12.5, 
7.9, 9.3, 15.5, 14.7, 12.9, 10.8, 14.5, 16.5)), .Names = c("Test", 
"Batch", "timepoint", "Status", "y"), row.names = c(NA, -20L), class = "data.frame")

dat通过提供图形aes,您可以对数据进行分组。如果组仅由一个成员组成,
geom_smooth
无法为该组打印任何内容

可能你想要这个:

geom_smooth(aes(shape=NA),method=lm, se=FALSE, size=1, linetype="twodash")

通过提供形状aes,可以对数据进行分组。如果组仅由一个成员组成,
geom_smooth
无法为该组打印任何内容

可能你想要这个:

geom_smooth(aes(shape=NA),method=lm, se=FALSE, size=1, linetype="twodash")

你能让你的例子重现吗?如果我们能玩它会更容易。你能让你的例子重现吗?如果我们能玩它会更容易。谢谢,我明白了!我不知道aes形状被认为是一个分组!谢谢,我明白了!我不知道aes形状被认为是一个分组!