Skip to content

graphics

2 messages · Karsten Rincke, Deepayan Sarkar

#
On 8/30/05, Karsten Rincke <rincke at physik.uni-kassel.de> wrote:
R likes data vectors to be columns, not rows.  With your data, you
could try


matplot(t(mydata[, 1:3]), type = 'b')


but it would probably make more sense to have the data in a different
format to begin with.  It could either be in the `wide' format:



Befragung   weiblich  maennlich
1           2.25      1.34
2           2.34      3.45
3           1.78      2.23


or the `long' format:


Befragung   y         Geschlecht
1           2.25      weiblich
2           2.34      weiblich
3           1.78      weiblich
1           1.34      maennlich
2           3.45      maennlich
3           2.23      maennlich



With the wide format you could use matplot as before, or use xyplot
from lattice:


mydata <-
    read.table(textConnection("
Befragung   weiblich  maennlich
1           2.25      1.34
2           2.34      3.45
3           1.78      2.23"), header = TRUE)

xyplot(maennlich + weiblich ~ Befragung,
       data = mydata,
       type = 'b',
       auto.key = TRUE)


With the long format, you could similarly do:


mydata <-
    read.table(textConnection("
Befragung   y         Geschlecht
1           2.25      weiblich
2           2.34      weiblich
3           1.78      weiblich
1           1.34      maennlich
2           3.45      maennlich
3           2.23      maennlich
"), header = TRUE)

xyplot(y ~ Befragung, data = mydata, groups = Geschlecht,
       type = 'b', auto.key = TRUE)


Hope that helps,

-Deepayan