Dear everybody, In our game-theory lesson we have run several classroom-experiments where the students had to decide for a natural number between one and seven. I have troubles now to visualize the results: be a the vector of answers. hist(a) will not assume natural numbers as answers, but rational. It will make the brakes exactly at the natural numbers, which is difficult to interpret, as only natural numbers may be employed. barplot(a) or barplot(a,1:7) will not aggregate the answers. If three students returned the number seven, it will show three bars to the size of seven instead one bar to the size of three on index seven. barplot(1:7,a), in this case, will show the bar at index seven, wut it will be to the hight of seven and to the width of three. I also wanted to show the results of the different versions of the experiment in ONE plot. As the number of participants varied I googled around in the R-Archives and got to recognize plot.edf. As a pitty, this function seems to set the index the wrong way round: the function starts with the number of students deciding for seven, but indexes them with one. Can anybody help me with these two problems? Thank you in advance!
On 6/26/05, Mag. Ferri Leberl <ferri.leberl at gmx.at> wrote:> Dear everybody, > > In our game-theory lesson we have run several classroom-experiments where the > students had to decide for a natural number between one and seven. I have > troubles now to visualize the results: be a the vector of answers. > > hist(a) will not assume natural numbers as answers, but rational. It will make > the brakes exactly at the natural numbers, which is difficult to interpret, > as only natural numbers may be employed. > > barplot(a) or barplot(a,1:7) will not aggregate the answers. If three students > returned the number seven, it will show three bars to the size of seven > instead one bar to the size of three on index seven. > > barplot(1:7,a), in this case, will show the bar at index seven, wut it will be > to the hight of seven and to the width of three. > > I also wanted to show the results of the different versions of the experiment > in ONE plot. As the number of participants varied I googled around in the > R-Archives and got to recognize plot.edf. As a pitty, this function seems to > set the index the wrong way round: the function starts with the number of > students deciding for seven, but indexes them with one. >Make sure that the data are factors so that numbers with 0 frequency still show up and then tabulate frequencies using 'table'. # test data x1 <- c(1, 1, 1, 2, 5, 6) x2 <- c(1, 3, 4, 5, 4) # tabulate frequencies ensuring that 0 frequencies are included x1t <- table(factor(x1, lev = 1:7)) x2t <- table(factor(x2, lev = 1:7)) # plot.table of x1t, barplot of x1t and barplot of both plot(x1t) barplot(x1t) barplot(rbind(x1t, x2t),beside = TRUE)
Mag. Ferri Leberl wrote:> Dear everybody, > > In our game-theory lesson we have run several classroom-experiments where the > students had to decide for a natural number between one and seven. I have > troubles now to visualize the results: be a the vector of answers. > > hist(a) will not assume natural numbers as answers, but rational. It will make > the brakes exactly at the natural numbers, which is difficult to interpret, > as only natural numbers may be employed.Read ?hist. The "breaks" argument allows you to control where the breaks occur. I'd guess you'd want hist(a, breaks = 0:7 + 0.5).> > barplot(a) or barplot(a,1:7) will not aggregate the answers. If three students > returned the number seven, it will show three bars to the size of seven > instead one bar to the size of three on index seven. > > barplot(1:7,a), in this case, will show the bar at index seven, wut it will be > to the hight of seven and to the width of three. > > I also wanted to show the results of the different versions of the experiment > in ONE plot. As the number of participants varied I googled around in the > R-Archives and got to recognize plot.edf. As a pitty, this function seems to > set the index the wrong way round: the function starts with the number of > students deciding for seven, but indexes them with one.There are many different ways to do this. You can have multiple panels in one plot with par(mfrow=...) or using the lattice package, you can overlap multiple histograms in one plot with "add=T" in the call to hist() (but the results don't look very good), you can construct multiple side-by-side histograms using barplot, etc. You should decide exactly what you want the plot to look like, then if you can't figure out how to draw it after reading the docs, ask here. Duncan Murdoch P.S. Your email address ferri.leberl at gmx.at fails with a "mailbox disabled" message.