0
votes

I am trying to use different colors for subgroups of genes in my ggplot. Currently, I used this script

ggplot() +
         geom_point(data=log2(gdat), aes_string(x="WT", y="mutant"),
                    col=ifelse(gdat$Rep==1, "blue", "gray"), alpha=3/10, size=2)+
           geom_point(data=log2(gdat), aes_string(x="WT", y="mutant"),
                      col=ifelse(gdat$Rep==2, "red", "gray"), alpha=3/10, size=2, shape=3)+
           geom_abline(intercept = 0, slope = 1) +
scale_x_continuous(trans='log2') +
            scale_y_continuous(trans='log2')

This is the last part of the script that I used to plot them. I have a group of genes in red and group of genes in blue. However, most of them falls into the group colored in gray (which covers the whole graph and makes the other two subgroups invisible). Is there a way to make this gray subgroup transparent, so the other two groups would be visible? Thanks all.

1
Can you make your problem reproducible and share gdat? Use dput.markus

1 Answers

2
votes

I try to help with a solution with some level of flexibility by mimickig what is done in R base plotting with plot() and points() calls.

# reproducible example dataframe
set.seed(1234)
a <- rnorm(1000)
df <- data.frame(wt = a,
                 mutant = 2*a+rnorm(1000),
                 rep = c(rep(1, 50), rep(2, 50), rep(3, 900)))

# plot
library(ggplot2)
ggplot(df) +
  geom_point(data=df[df$rep==3,], mapping=aes(x=wt, y=mutant), col="grey", size=4, alpha = 0.75)+
  geom_point(data=df[df$rep==1,], mapping=aes(x=wt, y=mutant), col="blue", size=4, alpha = 0.50)+
  geom_point(data=df[df$rep==2,], mapping=aes(x=wt, y=mutant), col="red", size=4, alpha = 0.25)

enter image description here