user1277593
user1277593

Reputation: 71

Plotting density plots on the negative y axis with ggplot2, R

I'm trying to plot densities on both sides of the x axis - trying to visualize reads mapping to both strands of a genomic region.

I have two problems :

  1. I want to use ggplot2 but

  2. I don't know how to extract the data from the plot object, or invert the plot that has already been made.

Any help greatly appreciated!

Upvotes: 0

Views: 1283

Answers (1)

joran
joran

Reputation: 173627

Your question is very unclear, but I found the "densities on both sides of the x axis" potentially interesting. So maybe you're trying to do something like this:

d <- data.frame(x = rnorm(1000),x1 = rnorm(1000,sd = 0.5))

ggplot(data = d,aes(x = x)) + 
    geom_density() + 
    geom_density(aes(x = x1,y = -(..density..)))

enter image description here

Upvotes: 6

Related Questions