在ggplot

时间:2018-05-04 18:47:59

标签: r ggplot2 annotations

我正在尝试创建一个ggplot,它将在情节上显示ttest的结果。我现在正在使用第annotate("text",x=1,y=10,label='atop(bold("P-value = 0.286"))',cex=7,parse=TRUE)行。唯一的问题是每次测试结果发生变化时我都必须手动更改值。我想在标签中插入ttest$p.value而不是数字,但请将其保留为粗体。 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用粘贴语句来帮助将动态p值放入注释步骤。这里的例子非常丑陋,但是你会明白这个想法,只需用你的ttest $ p.value替换注释步骤中的p_val:

library(circlize)

setwd("C:/Users/Main/Desktop/")
data <- read.table('./r_test.txt',header = FALSE,sep = '\t')

chordDiagram(data,annotationTrack="grid",grid.col = 
c("springgreen","coral","indianred","violet", 
"greenyellow","cyan","purple","firebrick", 
"gold","darkblue","red","magenta", 
"orangered","brown","blueviolet","darkgoldenrod",
"aquamarine","khaki"),preAllocateTracks=list(track.height = link.sort = 
TRUE,link.decreasing = TRUE)


circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) {
xlim = get.cell.meta.data("xlim")
xplot = get.cell.meta.data("xplot")
ylim = get.cell.meta.data("ylim")
sector.name = get.cell.meta.data("sector.index")
circos.text(mean(xlim), ylim[1], sector.name, facing = " niceFacing = TRUE, 
adj = c(0, .75),cex=2)
},bg.border = NA)