0

I'm trying to create one diagram with three histograms one beneath the other. The data is like this one:

dat <- read.table(header=TRUE, text="
A  rt
a1 825
a1 792
a1 840
a2 997
a2 902
a2 786
a3 888
a3 634
a3 783
")

With one grouping variable and the numeric variable reaction time. My task is to create three histograms for each grouping condition.

Here is a link how it is supposed to look in the end. Here the grouping variable is divided in "Simple", "Go/NoGo" and "Choice". As you can see it is not sufficient to create three histograms for each condition and put it under each other. enter image description here

I tried doing it like this:

hist(dat$rt~dat$A,seq(600,1000,100),freq=T)

but R returns the error message, that x has to be numerical.

I'm not allowed to use ggplot for this exercise, I'm not allowed to load any additional packages.

Maybe somebody can help me out! Thanks a lot!

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
natash
  • 127
  • 5
  • you can see [this](https://stackoverflow.com/a/34046049/11570343) – cdcarrion Sep 10 '20 at 17:30
  • Use this `par(mfrow = c(3, 1))` `hist(dat$rt[dat$A=="a1"],freq=T)` `hist(dat$rt[dat$A=="a2"],freq=T)` `hist(dat$rt[dat$A=="a3"],freq=T)` – cdcarrion Sep 10 '20 at 17:47
  • thank you, the problem is then it just gives me three separate histograms when I need one with the three included – natash Sep 10 '20 at 18:24
  • This should work `ggplot(dat, aes(rt, fill = factor(A)))+ geom_histogram(alpha = 0.5, aes(y = ..density..), position = 'identity')` – cdcarrion Sep 10 '20 at 19:05

0 Answers0