簡體   English   中英

將剝離點添加到bwplot(R中的格子圖形)

[英]Add stripplot points to bwplot (Lattice graphics in R)

##Example data to illustrate problem:
type=c("grp1","grp2","grp1","grp3","grp3","grp3","grp4")
num=c(1,1,2,4,3,5,1)
cols=c(rep("red",5),"green","red")

library(lattice)
bwplot(num~type)
par(new=T)
stripplot(num~type,col=cols)

我喜歡箱形圖顯示的其他信息,但我需要帶狀圖中的彩色點傳達的信息。 顯然par(new = T)不起作用,那么如何將點疊加到箱形圖中?

您可以這樣定義panel功能:

library(lattice)
bwplot(num~type,panel=function(x,y,...){
    panel.bwplot(x,y,...)
    panel.stripplot(x,y,col=cols,...)
})

在此處輸入圖片說明

agstudy的答案是相當不錯的,盡管正如我在評論中指出的那樣,由bwplot繪制的任何異常值也會由stripplot繪制,這可能會造成混淆。

請注意,僅當您使用jitter.data=TRUE作為jitter.data=TRUE的選項時, stripplot ,否則重復的點將直接在彼此之上繪制,並且您永遠不會知道它們在那里。 如果數據包含異常值,並且您使用jitter.data=TRUE ,那么您將看到的異常值是您應有的兩倍。

以下方法可抑制bwplot的異常值,從而避免出現此問題:

bwstrip <- function(x,y,...){
  panel.stripplot(x,y,col=cols,do.out=FALSE,jitter.data=TRUE,...)
  panel.bwplot(x,y,...)
}
bwplot(lobe.depths,panel=bwstrip)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM