繁体   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