对齐ggplot和基础图

时间:2017-01-26 01:31:58

标签: r plot ggplot2

我知道这可能是重复的,但我很绝望。

我使用ggplot生成了一个散点图,其数据如下所示:

SNP   Pvalue   POS
rs..  0.0023   3133333
rs..  0.0003   5000000

etc...

代码如下所示:

gg <- ggplot(snps) +                                                #dots
    geom_point(aes(x = nrow(snps), 
                   y = snps$POS, 
                   size = -log10(snps$Pvalue)),             
               color = 'black') +
    geom_text_repel(size = 3, # font size
                    aes(x = nrow(snps), 
                        y = snps$POS,
                        label = snps$SNP),
                    color = 'black',
                    point.padding = unit(0.5, "lines"),
                    segment.color = 'black') +
    theme_classic(base_size = 16) +
    scale_size("-Log10(Pvalue)", range=c(1,13), breaks = c(5,10,15,25,30,40,50,80,100,120,150,250,1900))

还使用使用plot的自定义函数。我已经生成了一个图表来显示特定染色体区域的基因。

基因的输入看起来像这样:

GENE   START         END   
X      3000000       3000123
Y      3109090       3200000
etc...

这个代码看起来像这样:

range <- length(genes.data)
offset <- range
gene.y.min <- offset
gene.y.max <- (offset/6)

gene.rows <- nrow(genes.data) * 2

min.pos <- min(genes.data$START)
max.pos <- max(genes.data$STOP)

image.type <- "pdf"
c <- runif(length(genes.data$START), min = 0, max = length(genes.data))
plot(c, genes.data$START, type = "n")
plot.genes(genes.data, min.pos, max.pos, gene.y.min, gene.y.max, gene.rows)

基本记住最后两行。对于base plot。各个图都按预期工作,我只想将它们合并在一起。他们使用相同的y-scale,但他们必须对齐。

我希望最终输出看起来像这样

-------------------------------
|     |                        |
|     |                        |
|base |         ggplot         |
|plot |                        |
|     |                        |
|     |                        |
|     |                        |
--------------------------------

两个图都使用相同的Y轴值。 20mb-30mb。所以我需要对齐信息

0 个答案:

没有答案
相关问题