我制作了这样的 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")