ggplot scatterplot and lines
1
1
Entering edit mode
6.6 years ago
Pin.Bioinf ▴ 340

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 • 2.5k views
ADD COMMENT
1
Entering edit mode

Not really a bioinformatics question. Ask on stackoverflow.

ADD REPLY
3
Entering edit mode
6.6 years ago
Buffo ★ 2.4k

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 COMMENT

Login before adding your answer.

Traffic: 1545 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