0

I am making a volcano plot of some metabolomics data with ggplot2. It is working well and I have it colored to reflect p-value and fold change cut offs. However I'd like the dots to be deferentially colored based on the value in the column 'variable'.

volcano = ggplot(foldpg, aes(x=log2fold, y=logp, colour=posthreshold)) +
  geom_point(alpha=0.5, size=2.5) +
 theme(legend.position = "none") +
xlim(c(-5, 5)) + ylim(c(0, 12)) +
xlab("log2 fold change") + ylab("-log10 p-value")
volcano

the "variable" column of foldpg has four possible values - I'd like a unique color for each.

Thanks

JHelander
  • 1
  • 1
  • 1
    color = posthreshold already colored your points, I don't think it's possible to color points based on both 'posthreshold' and 'variable'. – Sean Lin May 22 '17 at 22:21
  • 1
    you could use different shapes for 'variable' if you are coloring based on posthreshold. – Edgar Santos May 22 '17 at 22:38
  • 3
    Please provide some example data from `foldpg`. – neilfws May 22 '17 at 22:38
  • Please provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). If posting the data in the question is too cumbersome, post it in a github gist. You might be able to get the graphic your are looking for by using `colour = interaction(variable, posthreshold)` in the aesthetics. – Peter May 23 '17 at 15:51

1 Answers1

1

I generated a data frame foldpg with three variables

x=log2fold
y=logp
variable

the "variable" column of foldpg has four possible values A, B, C, D

log2fold<-runif(100, -1, 1)
logp<-runif(100, -5, 5)
variable<-sample( LETTERS[1:4], 100, replace=TRUE)
foldpg<- data.frame(variable, log2fold, logp)

with geom_point(aes(colour = variable)) you set the four colours while with scale_colour_manual you can assign the colours to the four values A, B, C, D.

volcano = ggplot(foldpg, aes(x=log2fold, y=logp)) +
  geom_point(aes(colour = variable), alpha=0.5, size=2.5) +
  scale_colour_manual(values = c("A"= "yellow", "B"="red",  "C"= 
  "black", "D"="green"))
volcano

However you will need to exclude colour=posthreshold

Al14
  • 1,734
  • 6
  • 32
  • 55