0

after searching for hours I will ask it directly here:

How do I rotate the labels of the x-axis in an effect-plot?

There is no problem in plotting the effect:

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

(where 'kiri' is a linear mixed effect model, made with lmer() and) it works with

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

Therefore, I try to plot vectors like this:

     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

In essence, the (statistical) effect of the RT is plotted respectively to the words and otherwords used.

But now there seems to be no way to rotate the labels on the x-axis. I tried las = 2 and other methods with par() without any changes to the plot - respectively, the x-axis - itself. I tried to plot it with ggplot() as well, but it didn't seem to work with the effects - or I didn't do it right.

I am thankful of any help.

Best, Kiri

Kiritschu
  • 1
  • 1
  • 1
    it will be helpful to others if you can provide a reproducible example. See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to create one. – mnm May 31 '18 at 11:44

1 Answers1

0

One possible solution with ggplot2 library is to use, element_text(). As you can see below the x-axis labels are clumped together.

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

clumpedupx-axislabels

Rotate the x-axis labels by applying element_text().

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

rotated-x-axis labels

So, change the value of angle in element_text() to get the desired result.

mnm
  • 1,962
  • 4
  • 19
  • 46
  • Hi, thank you for the fast answer. Unfortunately, it gives me an error message `Error: ggplot2 doesn't know how to deal with data of class eff` and I can't see what I need to see on a boxplot. Is there a possibility with a barplot? I tried it with this code, but still get the same error message. – Kiritschu Jun 01 '18 at 08:16
  • @Kiritschu it would be helpful to others if you can possible show us your dataset as well as your full code. I recommend that you take a look at this post and learn how to create a [minimum reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – mnm Jun 01 '18 at 08:32
  • I have to ask others if I am allowed to show my dataset here. But I will also take a look at your link. Thanks a lot. I will come back later, maybe with the dataset (and code). If it helps: It is eye-tracking data (reading/fixation time per word). – Kiritschu Jun 01 '18 at 09:48
  • @Kiritschu, there is no need for you to reveal the exact dataset. However, when you're creating the dummy dataset, ensure that it captures all the relevant columns that are there in your original dataset. For example, `data.frame(Y = rnorm(15), Z = ceiling(rnorm(15)))`. If you still do not understand, how to create dummy data, I suggest search on this site or else google it. you'll find ton's of examples. Once you've created a dummy dataset, I suggest to edit your question and reflect the same. Hope this helps. – mnm Jun 01 '18 at 10:43