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


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



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
gravatar for glihm
4.8 years ago by
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.


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