条形图中的 45 度 x 轴标签
45 degrees x axis labels in barplot
我知道此类问题已发布多次,但我尝试了所有不同的建议,但没有任何效果。我想让我的条形图上的 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))>
试试这个:
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"
,以便最初不打印标签。
我知道此类问题已发布多次,但我尝试了所有不同的建议,但没有任何效果。我想让我的条形图上的 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))>
试试这个:
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"
,以便最初不打印标签。