how to change colors in jitter plots (ggplot2)?
1
1
Entering edit mode
8.7 years ago
mbk0asis ▴ 690

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

R-plot

Thank you!

ggplot2 R jitter-plot • 8.9k views
ADD COMMENT
3
Entering edit mode
8.7 years ago
glihm ▴ 660

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 COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2606 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6