ggplot点图调整比例

时间:2017-06-15 05:33:26

标签: r ggplot2

我的数据看起来像

junc                    old         new
X:65961303-65965481(+)  0.025672937 0.004911527
3:90310183-90313113(-)  0.098444488 0.002132802
6:51414210-51415178(-)  3.05E-05    4.37E-06
10:79322700-79323569(+) 0.33095695  0.302002001
4:122972516-122973173(+)    0.939167683 0.932705233
4:53030079-53033983(+)  0.000233548 0.00081976
13:56185646-56189613(-) 4.85E-10    9.43E-09
13:56189703-56197485(-) 4.82E-07    6.96E-09
11:98577839-98579023(-) 0.001854774 0.000894136
10:90615925-90621493(-) 0.000902529 2.84E-05
10:19614164-19624369(-) 4.38E-08    1.26E-06

我想绘制一个点图,其中我的x轴是junc而y轴是值,每个junc理想情况下有两个点(新旧)

到目前为止我尝试过:

library(ggplot2)
library(reshape2)
dat <- read.delim('~/plot.txt', sep = '\t', header = F)
head(dat)
colnames(dat) = c('junc', 'old', 'new')
head(dat)
mdat <- melt(dat)
head(mdat)

 p = ggplot(mdat, aes(x=mdat$junction, fill=mdat$variable)) + geom_dotplot(binpositions="all")
 p 

获得的数字:enter image description here

如何调整比例并更改图表,以便我可以看到差异是每个junc的旧值和新值。

[编辑] 来自AK88建议的数字 enter image description here

编辑:

> head(mdat)
                   junc variable        value
1   X:65961303-65965481(+)       old 2.567294e-02
2   3:90310183-90313113(-)       old 9.844449e-02
3   6:51414210-51415178(-)       old 3.048876e-05
4  10:79322700-79323569(+)       old 3.309569e-01
5 4:122972516-122973173(+)       old 9.391677e-01
6   4:53030079-53033983(+)       old 2.335478e-04
> 
>head(mlt)
junc variable value
1   X:65961303-65965481(+)  variable   old
2   3:90310183-90313113(-)  variable   old
3   6:51414210-51415178(-)  variable   old
4  10:79322700-79323569(+)  variable   old
5 4:122972516-122973173(+)  variable   old
6   4:53030079-53033983(+)  variable   old

1 个答案:

答案 0 :(得分:1)

melt指定id.vars = "junc"

mdat = melt(dat, id.vars = "junc")

ggplot(data = mdat, aes(x = junc, y = value, color = variable)) +
  geom_point(position = position_dodge(width = 0.2))
相关问题