在具有不同幅度数据的圆形图表点内添加圆形折线图

时间:2018-03-15 15:13:03

标签: r ggplot2

我有一个名为mitodata的文件,有8388行,我写了一个例子来解释我的问题:

mitodata <-"Chr gene bp foldchange p
chrM chrM-1-2 2 -1.5 0.02
chrM chrM-3-4 4 1.5 0.05
chrM chrM-5-6 6 -1.2 0.0005
chrM chrM-7-8 8 1.3 0.02
chrM chrM-9-10 10 -1.6 0.007"
mitodata<-read.table(text=mitodata,header=T)

我可以轻松地为这些数据添加一些信息,用于绘制以曼哈顿绘图方式显示我的p值的圆形图,使用ggplot2如下:

# Load ggplot2
library(ggplot2)

#First adding a label for this exemple:  
addgenelabel <- function(bp,gene) { gene <- ifelse(bp < 2, gene <- "Control-Region", ifelse(bp < 4, gene <- "tRNA", ifelse (bp < 6, gene <- "12S", ifelse(bp < 8, gene <- "tRNA", ifelse(bp < 10, gene <- "16S", gene <- "Control-Region")))))}

# Add gene names to each SNP
    mitodata$gene <- addgenelabel(mitodata$bp,mitodata$gene)     
    # Creates and stores negative log p as a new variable
    mitodata$neglogp <- -1*log10(mitodata$p)
    # Adds a significance threshold line at negative log of 0.05
    mitodata$neglogpline <- -1*log10(0.05)
    # Adds -3 label to y axis
    mitodata$extraline <- -3
    # Set colors for each gene
    colours <- c("Control-Region" <- "deeppink", "tRNA" <- "green", "12S" <- "mediumaquamarine", "16S" <- "sienna4","red")

    lines <- data.frame(x = seq(0,10,by=1),y = 0)
    lines$gene <- addgenelabel(lines$x,lines$gene)

在此之后,我可以使用此命令进行绘图:

# Plot everything and GO
      p<- ggplot(mitodata, aes(x = bp,y = neglogp,color = gene)) +
      geom_point(size=0.5, alpha=1)+ coord_polar(direction = -1) +
      geom_line(aes(x,1.30,color = "black"),data = lines, linetype="dotted") +
      #facet_grid(.~pheno) +
      geom_line(aes(y=extraline)) +
      geom_point(aes(x,y,color = gene),data=lines, size=2) +
      scale_colour_manual(values = colours,"Genes",breaks = c("Control-Region","tRNA","12S","16S"),
      labels = c("Control-Region","tRNA","12S","16S")) + 
      theme(legend.justification=c(1,1), legend.position=c(0.98,0.98)) + theme(legend.text=element_text(size=10)) +
      xlab("Mitochondrial CpG Location") +
      ylab("-log(p-value)") +
      ggtitle("Negative Log P-value of Mitochondrial CpG Hits")


      ggsave("solarplot.tiff", w=12, h=12, dpi=600, compression = "lzw")

这样做,使用我的8388行数据,我得到了这样一个图:enter image description here

在我转换p值后,使用p的负对数,p值和foldchange的幅度相同。因此,在绘制图形时,两者都重叠。问题是我想在此图表中添加一个内部折线图,显示折叠更改列信息但不与p值信息重叠。像这样:

obs:根据定义的&#34;基因&#34;使这个图表改变颜色会很好。穿过圆圈 enter image description here

0 个答案:

没有答案