I'm looking at heterozygosity in windows across the genome. I have a value for each window and I want to plot these, alternating the colors of each chromosome (black and gray) to make it clearer. Additionally I would like to color significant values in red.
On the x axis I have chromosome, and on the y axis I have heterozygosity. I can color the significant values but I'm completely stuck on how to alternate between two colors. There are many values for each chromosome.
This is what I have so far:
plot(mydata$heterozygosity~mydata$chromosome,
xlab = "chromosome", ylab = "het", ylim = c(0, 0.35),
pch=ifelse(mydata$het > 0, 21, 26), bg=ifelse(mydata$het >0.1374, 'red', 'white'))
Please can anybody help?
Edit: Sorry! My plot so far is here:
and my example data is:
chromosome start end heterozygosity window
1 5920001 5960000 0.0569 219990
1 5930001 5970000 0.1009 219991
2 5940001 5980000 0.1099 219992
2 5950001 5990000 0.0768 219993
3 5960001 6000000 0.0392 219994
4 5970001 6010000 0.0354 219995
This is just a very short example because my real file is huge, but I basically have many entries for each chromosome and so I want to color those entries by their chromosome number. I hope this is clearer, please let me know if I'm still not making sense!
Your question is a little unclear. Can you please post a minimal reproducible example? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
Hey Alex, the user has somehow managed to reply here, on another thread: A: insert figure and code in the post of Biostars?
could you post some example data and your current output fig? Did you have a look at manhattan plot?
Please use the formatting bar (especially the
code
option) to present your post better. I've done it for you this time.Sorry I've now tried to make it clearer, thanks for the edits. I have looked at a manhattan plot but couldn't get it to work
I'm sorry, why have you added this as an answer? Does this belong in a comment or in a reply to an existing comment, perhaps?
My factor is ‘chromosome’ (I also want to make this plot for scaffolds). col=chromosome makes each chromosome a different color, but what I want is to alternate between two colors. I have done a lot of googling and wasn’t able to find an answer on how I do this. Is there a way to turn this into alternating colors?
Please use the
ADD COMMENT
button if you are not answering the top-level question.My understanding is that numbers window column are the difference between start and end positions. Is that correct? numbers in window column seem to be consecutively numbered @OP