0

all!

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?

Thank you!!!

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))

boxplots with geom_points

aosmith
  • 34,856
  • 9
  • 84
  • 118
mbk0asis
  • 99
  • 8
  • Possible duplicate of [Subset and ggplot2](https://stackoverflow.com/questions/18165578/subset-and-ggplot2) – TheSciGuy Jul 04 '18 at 16:02
  • guys, why is it so hard to create [an MCVE](https://stackoverflow.com/help/mcve) I am not so sure what you want, but I guess that this could be it: use `geom_point(aes(color = grp > 0 ))` – tjebo Jul 04 '18 at 21:27
  • ah. I just understood. You want conditional annotations, not different point colors. Please give us some data to play with, and we might be able to help better – tjebo Jul 04 '18 at 21:31

1 Answers1

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.

TheSciGuy
  • 1,154
  • 11
  • 22