我制作了一个对我来说几乎完美的图表。但我被困在如何从带注释的区域 geom_text() 中删除网格。我使用 geom_text 来绘制我的值和注释图。
我的图表如下所示:
我的数据:
structure(list(Mash_pear = c(0.328239947270445, 0.752207607551684,
0.812118104861163, 0.640824971449627, 0.615568052052443, 0.546635339103089,
0.557460706464288, 0.650480192893698, 0.418044504894929, 0.52962586938499,
0.727805116980878, 0.457751406173336, 0.429785015765779, 0.395830424689082,
0.442222743260579, 0.296983456365718, 0.80883682959008, 0.81208596690244,
0.710216015384062, 0.773625942359682), tRap_pear = c(0.0350096175177328,
0.234255507711743, 0.23714999195134, 0.185536020521134, 0.191585098617356,
0.201402054387186, 0.220911538536031, 0.216072802572045, 0.132247101763063,
0.172753098431029, 0.280795579672784, 0.188134155907737, 0.217454200485912,
0.0696965676717436, 0.233870791415384, 0.0544299934337156, 0.226678897883402,
0.128806853122092, 0.117478493999246, 0.161184511733104), Beeml_pear = c(0.179209909971615,
0.79129167285928, 0.856908302056589, 0.729078080521886, 0.709346164378725,
0.669599784720647, 0.585348196746785, 0.639355942917055, 0.544909349368496,
0.794652394149651, 0.863422091668162, 0.595508977637756, 0.533923256060852,
0.843786110234149, 0.402095177866003, 0.293984533306754, 0.867067527220569,
0.883565060756018, 0.727331622602897, 0.860485005688852), Mash_pear50 = c(0.192474082559755,
0.679726904159742, 0.778564545349054, 0.573745352397321, 0.56633658385284,
0.472559997318901, 0.462635414367878, 0.562128414492567, 0.354624921832056,
0.64532681437697, 0.699503386816393, 0.384318378224603, 0.366299448984722,
0.46938310547208, 0.282831366512569, 0.227004236832775, 0.754840213343737,
0.763285417222461, 0.638421127411269, 0.719475286983103)), .Names = c("Mash_pear",
"tRap_pear", "Beeml_pear", "Mash_pear50"), row.names = c("Aft1",
"Alx3_3418.2", "Alx4_1744.1", "Arid3a_3875.1_v1_primary", "Arid3a_3875.1_v2_primary",
"Arid3a_3875.2_v1_primary", "Arid3a_3875.2_v2_primary", "Arid5a_3770.2_v1_primary",
"Arid5a_3770.2_v2_primary", "Aro80", "Arx_1738.2", "Ascl2_2654.2_v1_primary",
"Ascl2_2654.2_v2_primary", "Asg1", "Atf1_3026.3_v1_primary",
"Atf1_3026.3_v2_primary", "Bapx1_2343.1", "Barhl1_2590.2", "Barhl2_3868.1",
"Barx1_2877.1"), class = "data.frame")
生成图表的代码:
plotAll<-function(data,size=2, alpha=0.4){
combs <- expand.grid(names(data), names(data))
out <- do.call(rbind, apply(combs, 1, function(x) {
tt <- data[, x]; names(tt) <- c("V1", "V2")
tt <- cbind(tt, id1 = x[1], id2 = x[2])
}))
library(plyr)
df.text=ddply(out[out$id1==out$id2,],.(id1,id2),summarise,
pos=max(V1)-(max(V1)-min(V1))/2)
out[out$id1==out$id2,c("V1","V2")]<-NA
out$labels <- rownames(out)
out$labels<-sapply(out$labels, function(x){
strsplit(x, "_")[[1]][1]
})
fam<-read.table('input/genomic_info_subset.tsv', sep='\t')
idx<-match(out$labels,fam$V1)
newcol<-fam$V4[idx]
newcol<-as.character(newcol)
out$fam<-newcol
require(ggplot2)
ggplot(data = out, aes(x = V2, y = V1)) +
geom_text(data = out[!is.na(out$V1),], aes(label = labels), size=size, alpha=alpha) + geom_abline( slope=1 ) +
facet_grid(id1 ~ id2, scales="fixed")+
geom_text(data=df.text,aes(pos,pos,label=id1), size=15) +
ggtitle("Corralation between measured & calculated affinities") +
ylab("") + xlab("") + theme(strip.text=element_blank(), strip.background=element_blank()) +
theme(plot.title=element_text(face="bold.italic",size="60", color="brown")) +
theme(axis.title=element_text(face="bold.italic",size="40", color="darkorange4"))
#return(out)
}
我想要的是从中间的注释图中删除斜线和网格,例如 Mash_pear、tRap_pear、Beeml_pear 和 Mash_pear50。我只想保留名称并删除斜率和网格,所以一个漂亮的白色/破碎的白色背景和只有文本注释。我试图将主题添加到我的函数之外的第二个 geom_text 的 aes 中,但这不起作用,我也尝试使用annotate()
而不是,geom_text()
但这给了我很多 aes() 错误等。