2013-10-02 61 views
2

我做一個GGPLOT2圖形是這樣的:爲什麼geom_smooth()會自動排除一些值?

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") 

,它給: enter image description here

有我的代碼來控制傳奇外觀等其他選項,但無處我曾問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") 
+0

可以讓你的例子可以重現?如果我們可以玩它,會更容易。 –

+0

完成,@RomanLuštrik。 –

回答

4

通過提供形狀AES你組的數據。如果該組僅由一個成員組成,則geom_smooth不能爲該組打印任何內容。

也許你想這樣的:

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

謝謝,我明白了!我不知道形狀aes被認爲是一個分組! –

相關問題