使用此代码时:
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初学者的课程或教程吗?
发布于 2016-04-27 07:30:35
提前抖动?
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

https://stackoverflow.com/questions/36882882
复制相似问题