首页 > 解决方案 > 使用旋转 X 轴在 R 中绘制效果图

问题描述

搜索了几个小时后,我会在这里直接问:

如何在效果图中旋转 x 轴的标签?

绘制效果没有问题:

kiri.eff <- Effect(c("words", "otherwords"), kiri)

(其中 'kiri' 是一个线性混合效果模型,由lmer()and 制成)它适用于

plot(kiri.eff, multiline = T, ci.style = "bars")

因此,我尝试绘制这样的向量:

     words        otherwords    RT
     word1        other1        1.67
     word1        other2        2.65
     word2        other1        1.8
     word3        other2        2
     word2        other2        1.4
     word3        other1        2.3

本质上,RT 的(统计)效果分别绘制到所使用的单词和其他单词上。

但是现在似乎没有办法在 x 轴上旋转标签。我尝试las = 2了其他方法,par()而没有对绘图进行任何更改 - 分别是 x 轴 - 本身。我也试着用它来绘制它ggplot(),但它似乎与效果无关——或者我做得不对。

我感谢任何帮助。

最好的,基里

标签: rggplot2rotationlabellme4

解决方案


使用库的一种可能解决方案ggplot2是使用element_text(). 正如您在下面看到的,x-axis标签聚集在一起。

library(ggplot2)
data(diamonds)
diamonds$cut <- paste("Super Dee-Duper",as.character(diamonds$cut))
q <- qplot(cut,carat,data=diamonds,geom="boxplot")
q 

clumpedupx 轴标签

通过应用 来旋转 x 轴标签element_text()

q + theme(axis.text.x = element_text(angle = 90, hjust = 1)) 

旋转 x 轴标签

因此,更改 in 的值angleelement_text()获得所需的结果。


推荐阅读