簡體   English   中英

使用ggplot2標記geom_jitter()的特定點

[英]Lable specific points of geom_jitter() by using ggplot2

使用此代碼時:

t1 <- ggplot(mtcars, aes(x=as.factor(cyl),y=mpg))
t2 <- geom_boxplot(outlier.shape=NA)
t3 <- geom_jitter(width=0.3, size=1.5, aes(color = disp))
t4 <- scale_colour_gradient(low="blue",high="red")
t5 <- geom_text(aes(label=ifelse(mpg > 30,as.character(mpg),'')))

t1 + t2 + t3 + t4 + t5

我得到了一個帶有抖動點的箱線圖。 但是,我也可以標記感興趣的點:標記不是在特定點旁邊,而是在箱線圖的垂直中間。

這是圖

知道如何將文本放置在對應點旁邊嗎?

非常感謝你們!

順便說一句:您能為我推薦ggplot2初學者的課程或教程嗎?

事先抖動嗎?

library(ggplot2)
set.seed(1)
t1 <- ggplot(transform(mtcars, xjit=jitter(as.numeric(as.factor(cyl)))), aes(x=as.factor(cyl),y=mpg))
t2 <- geom_boxplot(outlier.shape=NA)
t3 <- geom_point(size=1.5, aes(x=xjit, color = disp))
t4 <- scale_colour_gradient(low="blue",high="red")
t5 <- geom_text(aes(x=xjit, label=ifelse(mpg > 30,as.character(mpg),'')), vjust = 1)

t1 + t2 + t3 + t4 + t5

在此處輸入圖片說明

暫無
暫無

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

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