【问题标题】:Is there a way to rotate the x-axis labels in the visreg package?有没有办法旋转 visreg 包中的 x 轴标签?
【发布时间】:2021-01-27 11:50:02
【问题描述】:

*** 编辑 **** 想通了: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

【问题讨论】:

    标签: r graphics label axis visreg


    【解决方案1】:

    根据 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)))
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-06
      • 2019-04-21
      • 2019-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      相关资源
      最近更新 更多