在geom_point图中添加大于或小于0的点计数注释 [英] Add annotation of count of points greater or lower than 0 in geom_point plot
本文介绍了在geom_point图中添加大于或小于0的点计数注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
全部!
我已经成功地使用ggplot2生成了如下图,该图具有每个组中的总点数.如果要分别添加大于或小于0的点数,该怎么做?
I have managed to produce a plot like below using ggplot2 which have the total number of points in each group. If I want to add the number of points greater or lower than 0 separately, how can that be done?
谢谢!
give.n <- function(x){
return(c(y = 10, label = length(x)))
}
ggplot(dta, aes(x=type, y=foldChange, fill=grp)) +
geom_point(size=1,alpha=0.2,position = position_jitterdodge(jitter.width = .2),aes(col=grp)) +
geom_boxplot(alpha=0,outlier.shape=NA) + guides(fill=FALSE) + theme_bw() + xlab("") +
geom_hline(yintercept = 0,col="red") +
stat_summary(fun.data = give.n, geom = "text", fun.y = median, position = position_dodge(width = 0.75))
推荐答案
您可以在ggplot函数内部进行子集化,以绘制所需的内容.在您的情况下,如果您想要的值> 0
You can subset inside ggplot functions in order to plot whatever you want. In your case it would look like this if you wanted values > 0
ggplot(subset(dta, foldChange > 0), aes(x=type, y=foldChange, fill=grp))
我不确定您稍后再添加点到底是什么意思,但这至少应该过滤掉您想要的点.
I'm not sure what you mean exactly by adding the points later, but this should at least filter the points you desire.
这篇关于在geom_point图中添加大于或小于0的点计数注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文