Question: ggplot scatterplot and lines
1
gravatar for Pin.Bioinf
2.2 years ago by
Pin.Bioinf270
Malaga
Pin.Bioinf270 wrote:

Hello, I have methylation data, and I graph it as a scatterplot using ggplot like this:

p1<-ggplot(data, aes(meth_matrix$sample1, meth_matrix$sample3)) +
  geom_point() +
  theme_minimal()

which works perfect, but I want to add lines to it: the abline that divides the scatterplot in half:

p1  + geom_abline(color="blue")

and my question is: how can I draw two red lines parallel to that diagonal (y intercept would be 0.2, slope would be the same as the blue line) ??

Also: how can I draw the difference of both samples in a similar scatterplot (it will look like a horizontal scatterplot) with ggplot? right now I can only do it with plot like:

dif_samples<-meth_matrix$sample1- meth_matrix$sample3
plot(dif_samples, main="difference", 
     xlab="CpGs ", ylab="Methylation ", pch=19)

(also I'd like adding the horizontal blue line and the red lines paralllel to the blue line)

Please help!!!

Thank you very much.

ggplot scatterplot • 1.5k views
ADD COMMENTlink modified 2.2 years ago by Buffo1.8k • written 2.2 years ago by Pin.Bioinf270
1

Not really a bioinformatics question. Ask on stackoverflow.

ADD REPLYlink written 2.2 years ago by Nicolas Rosewick8.8k
3
gravatar for Buffo
2.2 years ago by
Buffo1.8k
Buffo1.8k wrote:

To add lines in ggplot:

horizontal:
geom_hline(yintercept=0.2, linetype="dashed", color = "Black") 

Vertical;
geom_vline(xintercept = c(-3,3), linetype="dashed", color = "black")

ablines in plot():

abline(h = 0.2, v = c(-3,3), lty = 2, col= "Black")
ADD COMMENTlink written 2.2 years ago by Buffo1.8k
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: 1262 users visited in the last hour