【问题标题】:how do i get a 45 angle for the x axis labels in the following code [duplicate]如何在以下代码中为 x 轴标签获得 45 角 [重复]
【发布时间】:2025-12-01 23:45:02
【问题描述】:

可能重复:
Rotate X Axis Labels of twoord.plot in R

以下代码运行良好。我希望 xlabels 的角度为 45,因为它们很长,我不想改变那里的大小(我需要全名)。

mp <- barplot(v,names.arg = c("Lung Lavage Fluid","Erythroleukemic Cell Line", "Blood Plasma","T - Cell Cell Line","Liver Whole Cell","B - Lymphocytes", "panc","prostate","Bladder Urine"),cex.names=0.65,col = c(1,2,3,4,5,6,7,8,9), main = val2,density = 50,angle = 45,xlab = "TISSUE",ylab = "EXPRESSION VALUE", ,border = "blue");

palette(c('blue','green','red','pink','brown','coral','deepskyblue','yellow','yellowgreen'));

【问题讨论】:

标签: r axis-labels


【解决方案1】:

AFAIK,对于基本图形,您只能要求 x 或 y 轴上标签的 0/90° 方向(请参阅 par() 中的 las 参数)。但是,使用 latticeggplot2 您可以做到。

这是lattice::barchart() 的示例:

tt <- table(sample(LETTERS[1:6], 100, rep=T))
library(lattice)
barchart(tt, horiz=F, 
         scales=list(x=list(rot=45, labels=paste("Fancy label", 1:6))))

用您自己的标签替换labels,或者如果您已经有一个命名表,请保持原样。

【讨论】:

  • 使用 ggplot2,这可以通过添加 + opts(axis.text.x = theme_text(angle =45) 到你的情节来完成