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

3
  • Possible duplicate of Subset and ggplot2 Commented Jul 4, 2018 at 16:02
  • guys, why is it so hard to create an MCVE I am not so sure what you want, but I guess that this could be it: use geom_point(aes(color = grp > 0 )) Commented Jul 4, 2018 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 Commented Jul 4, 2018 at 21:31

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.