# [R] Plotting averages of y per x

Gregor GORJANC gregor.gorjanc at bfro.uni-lj.si
Fri Nov 19 18:48:22 CET 2004

```Hello!

I often plot average of y instead of all y values, since one can easily
see the trend if there is to many points and/or x might be like 1, 2, 3,
4, 5, ... and you might get a cloud (which can also be informative)
and/or columns of points.

Anyway, learning with R i get stucked. I have the data in table
burnins1, with the following names:

names(burnins1)
[1] "Model"       "Replication" "h2"          "burnin"

and some data
...
...
380    New          80  2     23
381    New          81  5     38
382    New          82 10     31
383    New          83 15     98
384    New          84 20     32
385    New          85 40     30
386    New          86  1     43
387    New          87  2     53
388    New          88  5     36
389    New          89 10     51
390    New          90 15     19
...
...

So I want to plot mean of variable burnin by variables model and h2. I
compute means with

tmp <- as.data.frame(t(tapply(burnin, list(Model, h2), mean)))

and table tmp looks like this

Old   New
1  31.00 29.36
2  30.30 28.34
5  32.92 30.66
10 39.00 37.54
15 40.66 34.07
20 39.29 35.94
40 28.63 28.51

Now I want to launch something like
plot(tmp[, 0], Old)
points(tmp[, 0], New, pch = 20)

and it gives me the error

Error in pairs.default(x, ...) : non-numeric argument to pairs

I guess that I am having problem with tmp[, 0]. If I use

plot(Old)
points(New, pch = 20)

I get the plot, but abscisa is numbered from 1 to 7 not 1, 2, 5, 10, 15,
20 and 40. Does anyone have any sugestions?

I would also like to produce table like this, so plotting would be
easier, since there would be no need to use points() and/or lines()

Model h2 mean
1  Old  1  31.00
2  Old  2  30.30
3  Old  5  32.92
4  Old  10 39.00
5  Old  15 40.66
6  Old  20 39.29
7  Old  40 28.63
8  Old  1  29.36
9  Old  2  28.34
10 Old  5  30.66
11 Old  10 37.54
12 Old  15 34.07
13 Old  20 35.94
14 Old  40 28.51

--
Lep pozdrav / With regards / Con respeto,
Gregor GORJANC

---------------------------------------------------------------
University of Ljubljana
Biotechnical Faculty       URI: http://www.bfro.uni-lj.si
Zootechnical Department    mail: gregor.gorjanc <at> bfro.uni-lj.si
Groblje 3                  tel: +386 (0)1 72 17 861
SI-1230 Domzale            fax: +386 (0)1 72 41 005
Slovenia

```