How to put groups of rotated x-labels in labeled brackets, here is an example:
这是一个Wego Web工具的结果,但我想在R中做.
我知道它在x轴下添加线段,但我没有得到每个标签的末端来绘制线段.
How to put groups of rotated x-labels in labeled brackets, here is an example:
这是一个Wego Web工具的结果,但我想在R中做.
我知道它在x轴下添加线段,但我没有得到每个标签的末端来绘制线段.
它不一定很漂亮,因为它大多是硬编码的,但它可能会给出一个大致的 idea ,并成为一个开始.其 idea 是在文本上涂上gsub
个,从而在segments
上涂上白色的ASCII框.
cls <- c('#8E83C0', '#7F004B')
png('foo.png', 600, 500)
par(mar=c(17, 5, 4, 6))
## barplot
b <- barplot(M, beside=TRUE, col=cls, log='y', ylim=c(0.1, 100), yaxt='n', border=cls, ylab='Percent of genes')
cb <- colMeans(b)
axis(side=1, at=cb, labels=FALSE, srt=45, tck=0)
axis(side=2, at=c(.1, 1, 10, 100), las=2)
axis(side=4, at=c(.1, 1, 10, 100), labels=c(.1, 1, 10, 100)*200, las=2)
mtext(side=4, line=3, 'Number of genes')
box()
legend('topleft', pch=15, col=cls, legend=c('Rice', 'Arabidopsis'), bty='n')
## selections
s <- matrix(c(1, 3, 4, 15, 16, 18), 2)
segments(cb[s], .08, cb[s] - 6, .0002, cex=10, xpd=TRUE) ## draw diagonal lines
text(x=colMeans(b), y=0.08, labels=gsub('.', '\u{2588}', labs), col='white', ## delete text background
xpd=TRUE, srt=75, adj=1, cex=.45, font=2)
text(x=colMeans(b), y=0.08, labels=labs, xpd=TRUE, srt=75, adj=1, cex=.8) ## add text
segments(cb[s[seq_along(s) %% 2 == 1]] - 6, .0002, cb[s[seq_along(s) %% 2 == 0]] - 6, ## horiz. lines
xpd=TRUE)
text(x=cb[colMeans(s)] - 4, .00015, ## add labels
labels=c('Cellular location', 'Molecular function', 'Biological process'), xpd=TRUE)
dev.off()
Data:个
M <- structure(c(2.80726227650382, 2.64256293274864, 7.0102982246191,
7.5018148086326, 25.6501702479728, 25.0712633160012, 4.68983170461288,
4.70906566370853, 0.884917181175275, 0.937570946155162, 20.7375441378035,
20.1152922600914, 56.670251722557, 56.2605524666463, 3.94515839835875,
4.01074867385038, 9.16121956424095, 8.91395744490961, 26.8659730117826,
27.8972725231774, 14.8268139881184, 15.3903380377903, 0.25900960776686,
0.258869902594842, 29.8213455626689, 29.4996857430132, 13.5915802573365,
14.3385613824498, 36.6442873514434, 35.5400788324485, 0.233886747548567,
0.22457963117021, 11.5138271223363, 12.3439712437831, 10.4035068344801,
10.2619581657598), dim = c(2L, 18L))
labs <- c('biological regulation', 'cellular process', 'detoxification', 'developmental process',
'growth', 'homeostatic process', 'immune system process', 'localization', 'locomotion',
'metabolic process', 'multicellular organismal process', 'negative regulation of biological process',
'pigmentation', 'positive regulation of biological process', 'regulation of biological process',
'reproduction', 'reproductive process', 'response to stimulus')