2

我制作了这样的 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()排除某些值,并且如您所见,它会自动排除具有Status=="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")
4

1 回答 1

4

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

可能你想要这个:

geom_smooth(aes(shape=NA),method=lm, se=FALSE, size=1, linetype="twodash")
于 2013-10-02T09:33:12.767 回答