用ggplot2,R在负y轴上绘制密度图
问题描述:
我正在尝试在x轴的两侧绘制密度-试图可视化映射到基因组区域的两条链的读段.
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.
我有两个问题:
-
我想使用
ggplot2
但
我不知道如何从绘图对象中提取数据,或者反转已经制作的绘图.
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!
答
您的问题还不清楚,但是我发现"x轴两侧的密度"可能很有趣.因此,也许您正在尝试执行以下操作:
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..)))