This is a test version of Biostars. For the public version, visit https://www.biostars.org.
help with ggplot

So here's the snip of the ORA result provided to me and I want to plot dotplot using ggplot.

snip

ggplot(data = test12,
  aes(x = Condition, y = GO, size = FoldChange)
  ) + 
  geom_point(aes(color = 'P-value')) + 
  scale_color_gradient(low = "blue", high = "red")

It's giving me error: Discrete value supplied to continuous scale

Any idea what I might be doing wrong. Any help is appreciated!

ggplot

What is the output to:

class(test12$GO)
class(test12$Condition)
unique(test12$Condition)

But before that, why are you trying to set color using a continuous value? Shouldn't you bin the p-value then set a color based on, say, if the pvalue < 0.05 or >=0.05?

oh hey, they are as follow:

 - class(test12$GO) = character
 - class(test12$Condition) = character
 - unique(test12$Condition) = "+" "-"

I am so sorry but I am not sure what you mean by continuous value and bin the p-value, also, results are taken from DAVID I guess so only p-value of <0.05 are exported

1 answer

It could be that your p-value is of character class. Check that. Your code works fine in my example:

dat12 <- data.frame(
  GO=LETTERS[1:6],
  Condition = c("+","-","+","-","+","-"),
  FoldChange = sample(1:10,6),
  pvalue = c(4.2E-02, 2.05E-02, 1.89E-03, 1.44E-02, 1.78E-06,7.04E-03)
)

dat12
  GO Condition FoldChange   pvalue
1  A         +          8 4.20e-02
2  B         -         10 2.05e-02
3  C         +          6 1.89e-03
4  D         -          4 1.44e-02
5  E         +          3 1.78e-06
6  F         -          2 7.04e-03

ggplot(dat12,
  aes(x = Condition, y = GO, size = FoldChange)) + 
  geom_point(aes(color=pvalue)) + 
  scale_color_gradient(low = "blue", high = "red")

plot

Oh heya, So I copy pasted necessary things in a new excel, loaded it and checked the class of pvalue (it's numeric) and still getting the same error of supplying discrete value to continuous scale :(

I have no clue how, but I tried using your code, and it somehow worked!!! Thanks a lot. I tried it with another datasheet too and it is working, I Can't thank you enough

It should be fun trying to figure out why your initial code/dataset did not work. I've moved my comment to an answer - please accept it to resolve the post.

I am definitely trying that!! And done! Thanks again!!

Log in to answer this question.