Question: ggplot scatterplot and lines

1

Pin.Bioinf •

**240**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.

ADD COMMENT
• link
•
modified 14 months ago
by
Buffo •

**1.6k**• written 14 months ago by Pin.Bioinf •**240**
Not really a bioinformatics question. Ask on stackoverflow.

7.6k