This is a test version of Biostars. For the public version, visit https://www.biostars.org.
ggplot scatterplot and lines

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

Not really a bioinformatics question. Ask on stackoverflow.

1 answer

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")

Log in to answer this question.