Question: how to change colors in jitter plots (ggplot2)?
0
gravatar for mbk0asis
4.8 years ago by
mbk0asis530
Korea, Republic Of
mbk0asis530 wrote:

Hi.

I made a jitter plots with 3 data set overlaied in a single plot. What I tried to do was setting each data different colors, but the colors weren't changed right. The colors seemed to be automatically assigned to each data set. Does anyone know the reason here? 

here's the R code

ggplot(All,aes(x=chr,y=log10_FI.MI))+guides(colour=FALSE)+ylim(c(-1.5,1.5))+geom_jitter(alpha=1,size=2,position=position_jitter(width=0.4),aes(color="blue"))+geom_jitter(data=All,aes(x=chr,y=log10_FN.MI,color="red"),alpha=0.5,size=2,position=position_jitter(width=0.4))+geom_jitter(data=All,aes(x=chr,y=log10_MN.MI,color="grey"),alpha=0.5,size=2,position=position_jitter(width=0.4))

 

and the plot

 

Thank you!!!

 
ggplot2 jitter plot R • 3.3k views
ADD COMMENTlink modified 4.8 years ago by glihm620 • written 4.8 years ago by mbk0asis530
2
gravatar for glihm
4.8 years ago by
glihm620
France
glihm620 wrote:

Hi there, 

I think you are not using ggplot2 as you have to. To represent data with ggplot2, you have to set your data to long format, it means all samples in the same data-frame.
In your case, the data frame will be:

sample_name           chromosome             log10_FI.MI
sample1                   1                     -1
sample1                   2                     +1
....
sample2                   1                    -0.5
sample2                   2                    +0.24
....
sample3                   1                      +1
....

You see? Then, when you will plot your data, in "aes", you will choose "color = sample_name" if you want to attribute a color for each one. However, if you want your proper color, you can use a vector "color = c("red", "blue", "green")".
 

ADD COMMENTlink written 4.8 years ago by glihm620

Thank you! So where should I put the vector colors? I'm a newbie, so please bear with me...

ADD REPLYlink written 4.8 years ago by mbk0asis530
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1878 users visited in the last hour