NewUsr_stat
NewUsr_stat

Reputation: 2571

Overlay information ggplot

I'm trying to add two different scales of colours to my data.

I have a data.frame that looks like this:

    Exp1       Exp2      Cells    Sample colors
 -3.4397902   10.058648 0.2666572  5_2   yellow
  0.992361    4.272414  0.0000000  7_1   pink
  3.2959178   7.605405  0.4300744  5_2   yellow
 -6.7069208   5.652064  0.0000000  7_1   pink
 -2.5130817   3.703727  0.0000000  7_1   pink
 -8.5677462   7.570862  0.0000000  5_2   yellow 

To do this I used the following piece of code:

ggplot(mydata) +
  geom_point(aes(Exp1, Exp2, color=Cells))  +
  geom_point(aes(Exp1, Exp2, group=colors, alpha=colors), size=1) + scale_colour_gradient2(low="blue",mid="orange" , high="pink")

I'm able to plot the gradient but I'm not able to plot yellow dots and pink dots according to the Sample of origin.

Can anyone help me please?

Thank you in advance

Upvotes: 1

Views: 31

Answers (1)

Roman
Roman

Reputation: 17648

You can try to work with fill and color independently

ggplot(d) +
  geom_point(aes(Exp1, Exp2, color=Cells))  +
  geom_point(aes(Exp1, Exp2, fill=colors), shape=21, size=1) + 
  scale_fill_manual(values = c("pink", "yellow")) +
  scale_colour_gradient2(low="blue",mid="orange" , high="pink")

enter image description here

Upvotes: 2

Related Questions