[英]How can I add text labels showing the amount of data points in a geom_jitter plot?
[英]How not to plot all points of geom_jitter?
我還有一個關於geom_boxplot的問題。 有可能不為異常值繪制geom_jitter嗎? 這樣,我可以在一種顏色中具有離群值,而在另一種顏色中具有抖動點
aa <- c(rep("A1",5), rep("A2",3), rep("A3",4), rep("A4",9), rep("A5",3))
aa <- as.factor(aa)
per <- runif(length(aa), min=0, max=100)
per <- trunc(per)
z <- data.frame(x=aa,y=per)
z$ch <- NA
z[z$x %in% c("A1","A2"), "ch"] <- "string1"
z[z$x %in% c("A3"), "ch"] <- "string2"
z[z$x %in% c("A4", "A5"), "ch"] <- "string3"
z$ch <- as.factor(z$ch)
z$x = with(z, factor(x, rev(levels(x))))
p <- ggplot(z, aes(x, y, fill = ch)) +
geom_boxplot(size = 0.2, position = "dodge", outlier.colour = "red", outlier.shape = 16, outlier.size = 2) +
geom_jitter(size=1,position = "dodge") +
opts(legend.position = "right") +
scale_colour_hue("variable") +
coord_flip()
print(p)
在數據集z
添加is.outlier
列(當且僅當該值是異常值時才為TRUE
)。 如果您想對異常值以外的所有事物執行某項操作,請在非異常值子集中添加數據參數,例如,
geom_jitter(some_stuff, data = subset(z, !is.outlier))
不要做不同的事情,異常值和非離群值,使用is.outlier
在你的審美,比如,
geom_point(aes(size = is.outlier + 1))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.