条形图中的45度x轴标签

时间:2015-12-03 19:40:16

标签: r rotation axis labels

我知道这类问题已被多次发布,但我尝试了所有不同的建议,对我来说没有任何作用。我希望我的条形图上的x轴标签位于45度。我的代码目前是这样的:

barplot(t(all.vac_models01[1:28,3:4]), ylab = expression("Proportion of "*italic("R"^"2")),
las=2, cex.names = 0.9,
legend.text = gsub("prop_attributed_to_visit", "Intraindividual", 
gsub(pattern = "prop_attributed_to_patientID", 
replacement = "Interindividual", colnames(all.vac_models01[1:28,3:4]))), 
args.legend = list(x= 30, y = 1.3, xpd = T, horiz = T, bg = "white", bty ="o", box.lwd = 0))>

1 个答案:

答案 0 :(得分:1)

试试这个:

x <- barplot(t(all.vac_models01[1:28,3:4]), ylab = expression("Proportion of "*italic("R"^"2")),
        las=2, cex.names = 0.9,
        legend.text = gsub("prop_attributed_to_visit", "Intraindividual", 
                           gsub(pattern = "prop_attributed_to_patientID", 
                                replacement = "Interindividual", colnames(all.vac_models01[1:28,3:4]))), 
        args.legend = list(x= 30, y = 1.3, xpd = T, horiz = T, bg = "white", bty ="o", box.lwd = 0),
        xaxt="n")
labs <- names(t(all.vac_models01[1:28,3:4]))
text(cex=1, x=x, y=-1.25, labs, xpd=TRUE, srt=45, pos=2)

barplot电话分配给x,可以存储标签的位置。请务必指定xaxt="n",以便最初不打印标签。