我有这个代码来创建条形图,但我想将x轴中的名称更改为种类名称,例如,我想让字体更小,以便我可以适应它。我大道尝试以各种组合使用cex功能,但没有奏效。我很感激你的建议吗?
count <-
matrix(c(16,102,11,106,15,95,26,87,18,99,21,103,12,110,30,103,10,107,20,87,13,110,17,93), nrow = 2)
barplot(count, beside=T, legend =T, ylim=c(0,130),
col=c("darkolivegreen3", "firebrick1"),
ylab="Frequency (no. of moths)", las = 3,
names = c("tiger\nCo", "tiger\nCr" , "eyes\nCo", "eyes\nCr", "mottled\nCo","mottled\nCr", "pepperL\nCo","pepperL\nCr", "pepperD\nCo","pepperD\nCr", "convol\nCo", "convol\nCr"))
legend(6,130, legend=(c("survived","predated")), pch=c(15,22), cex=0.8, col=c("darkolivegreen3","firebrick1"))
答案 0 :(得分:7)
嗯,根据?barplot
页面,有一个cex.names
参数:
barplot(count, beside=T, legend =T, ylim=c(0,130),
col=c("darkolivegreen3", "firebrick1"),
ylab="Frequency (no. of moths)", las = 3,
cex.names=0.8,
names.arg = c("tiger\nCo", "tiger\nCr" , "eyes\nCo", "eyes\nCr",
"mottled\nCo","mottled\nCr", "pepperL\nCo",
"pepperL\nCr", "pepperD\nCo","pepperD\nCr",
"convol\nCo", "convol\nCr"))
legend(6,130, legend=(c("survived","predated")), pch=c(15,22),
col=c("darkolivegreen3","firebrick1"))
我承认找到正确的cex。*参数有时很困难,有时需要单独调用轴,但这里看起来似乎微不足道。