有没有办法在 visreg 包中旋转 x 轴标签?

Is there a way to rotate the x-axis labels in the visreg package?

*** 编辑 **** 弄明白了:scales = list(rot = 90)

我正在使用 visreg() 函数绘制一个线性模型来比较不同年份的鸟类体重。我有三个不同的物种,所以图表非常拥挤。我想旋转 x 轴标签,使它们垂直,但我不知道该怎么做。我在许多地方使用了 las = 2,但无济于事。帮助将不胜感激!谢谢。

 visreg(hawk_lm1, xvar = "Year", by = "Species", whitespace = 0.4, las = 2,
       points.par = list(cex = 0.5, col = "grey")) 

A screenshot of the graph as it is at the moment

根据 visreg 包的文档,如果您使用 by= 参数,则绘图是使用 lattice 包制作的。在 Lattice 中,您可以使用 scales= 参数和 rot() 一起旋转轴,只需将参数作为附加参数包含在 visreg 函数中,它就可以完成这项工作。我从空气质量数据集创建了这个例子来说明。

library(visreg)
airquality$Heat <- cut(airquality$Temp, 3, labels=c("Cool", "Mild", "Hot"))
fit <- lm(Ozone ~ Solar.R + Wind + Heat, data=airquality)

##default  x axis labels
visreg(fit, "Wind", by="Heat",  bty="n", ylab="Ozone")

##rotated x  axis labels
visreg(fit, "Wind", by="Heat",  bty="n", ylab="Ozone", scales=list(x=list(rot=90)))