NewUsr_stat
NewUsr_stat

Reputation: 2583

Merge information on the same plot

I have some data that looks like this:

  Expression1    Expression2  CellType  Patient   
     9.34          8.23         3.2      A
     8.2           3.2         10.9      B      
     2.12          5.3         12.9      B    
     2.10          1.3          2.9      B    
     2.12          1.5          2.9      A    
     2.11          9.5          6.9      A    

... .... ... ... ....

I would like to generate a plot (with ggplot) with Expression1 and Expression2 on the y and x axes respectively and dots coloured in a gradient of a single color according to the CellType column and at the same time distinguishing between Patient A and B on the same plot.

Can anyone help me please?

ggplot(myDF, aes(Expression1, Expression2)) +  geom_point(aes(colour = CellType)) + scale_colour_gradient2(low="black",mid="white" , high="red", + ggtitle("First_attempt")

I don't know how to add a gradient for Patient

Thank you in advance

Upvotes: 1

Views: 40

Answers (1)

Gautam
Gautam

Reputation: 2753

The below seems to work fine:

dt <- data.table::fread('Expression1    Expression2  CellType  Patient   
     9.34          8.23         3.2      A
           8.2           3.2         10.9      B      
           2.12          5.3         12.9      B    
           2.10          1.3          2.9      B    
           2.12          1.5          2.9      A    
           2.11          9.5          6.9      A ')

library(ggplot2)
ggplot(dt) + geom_point(aes(x = Expression2, y = Expression1, 
                            color = CellType, shape = Patient))

output

plot

Upvotes: 1

Related Questions