Genoa
Genoa

Reputation: 1

Filling in points by color gradients and size ggplot2 in R

I am trying to make a weighted scatter-plot where the plot is ordered from the Pathway with the highest Score to the Pathway with the lowest. I am also attempting to change the color of the plot based on the P-value, but it plots numbers with larger P values with darker color. However, I wish to change the color gradient so that smaller P = darker and larger P = lighter

head(table):

     Pathway         Score     P-value
1    Interferon      1.5       0.0001
2    Cytokine        1.2       0.003
3    TLR             1.2       0.0022
4    Complement      1.1       0.0021
5    Growth factor   1.0       0.002
6    Glucose         1.0       0.001

Code is:

ggplot(my_table, aes(x = Score, y = reorder(Pathway, Score), size = Score, fill = P-value)) + 
    geom_point(shape = 21)

How can I do that?

Upvotes: 0

Views: 1095

Answers (1)

rnso
rnso

Reputation: 24545

One can change the color of the continuous variables using scale_color_gradient in ggplot. Adding following works to have lower values with darker color and higher values with lighter color:

+ scale_color_gradient(low = "blue", high = "yellow")

Upvotes: 1

Related Questions