[R] plot different groups as factors

Duncan Mackay dulcalma at bigpond.com
Thu Dec 19 13:32:38 CET 2013


Hi Luigi

A quick guess with lattice

library(lattice)

structure(list(time = c(18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
12, 12, 12, 12, 12, 12, 12, 12), clas = c("medium", "medium", 
"medium", "medium", "medium", "medium", "medium", "medium", "medium", 
"medium", "medium", "medium", "medium", "medium", "high", "high", 
"high", "high", "high", "high", "high", "low", "low", "low", 
"low", "low", "low", "low", "medium", "medium", "medium", "medium", 
"medium", "medium", "medium", "medium", "medium", "medium", "medium", 
"medium", "medium", "medium", "medium", "medium", "medium", "medium", 
"high", "high", "high", "high", "high", "high", "high", "high", 
"high", "high", "low", "low", "low", "low", "low", "low", "low", 
"low", "low", "low"), value = c(2.92, 0.01, 0.36, 3.16, 0.99, 
0.38, 0.01, 5.1, 0.04, 0.01, 1.33, 4.13, 0.15, 0.15, 14.18, 4290.14, 
26.8, 5.33, 17.58, 14.29, 248.5, 0.01, 0, 0, 0, 0, 0, 0, 0.151395382, 
5.327863403, 5.10096383, 1.32567787, 4.352404124, 0.458606982, 
2.915908912, 0.011996374, 0.364710382, 0.033016026, 3.161701212, 
0.381564497, 0.010971385, 0.035646472, 0.014781805, 4.129708296, 
0.153094117, 0.018497847, 15.09178491, 17.58393041, 14.17643928, 
4290.143561, 26.79730719, 294.6367065, 14.2888441, 248.495231, 
209.3131795, 2014.506722, 0.010751273, 0.002325138, 0.000637473, 
0.003984336, 0.006018154, 0.003620907, 7.45936e-05, 0.000142311, 
0.002460417, 0.001280189)), .Names = c("time", "clas", "value"
), row.names = c(NA, -66L), class = "data.frame")

bwplot(value~factor(time)|factor(dat$clas, levels =
c("low","medium","high")),dat, hor=F, layout = c(3,1),scales = list(relation
= "free") )

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au





-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Luigi Marongiu
Sent: Thursday, 19 December 2013 10:19
To: r-help at r-project.org
Subject: [R] plot different groups as factors

dear all,
i would like to plot the value of different response groups. when i simply
use  plot(y ~ x) i obtain a series of boxplots. i would rather use dots. i
also tried with stripchart(y ~ x), which gives better results but does not
place properly the labels since place them alphabetically.
in addition i actually have 6 response groups: 3 classes (low, medium,
high) and 2 sampling time (12 and 18 months).
how can i generate these individual groups and plot them in the correct
order (low, medium, high and 12, 18)? i believe is something to do with the
factors but i don't know how to implement them.
what i am looking for is to generate a figure such as the one i sketched in
the attached file. i also attached a dataframe version of my data. the
vectors containing the same data are:
time <-c(  18,    18,    18,    18,    18,    18,    18,    18,    18,
18,    18,    18,    18,    18,    18,    18,    18,    18,    18,
18,    18,    18,    18,    18,    18,    18,    18,    18,    12,
12,    12,    12,    12,    12,    12,    12,    12,    12,    12,
12,    12,    12,    12,    12,    12,    12,    12,    12,    12,
12,    12,    12,    12,    12,    12,    12,    12,    12,    12,
12,    12,    12,    12,    12,    12,    12)
class <-c(    medium,    medium,    medium,    medium,    medium,
medium,    medium,    medium,    medium,    medium,    medium,
medium,    medium,    medium,    high,    high,    high,    high,
high,    high,    high,    low,    low,    low,    low,    low,    low,
low,    medium,    medium,    medium,    medium,    medium,    medium,
medium,    medium,    medium,    medium,    medium,    medium,
medium,    medium,    medium,    medium,    medium,    medium,    high,
high,    high,    high,    high,    high,    high,    high,    high,
high,    low,    low,    low,    low,    low,    low,    low,    low,
low,    low)
value <-c(    2.92,    0.01,    0.36,    3.16,    0.99,    0.38,
0.01,    5.1,    0.04,    0.01,    1.33,    4.13,    0.15,    0.15,
14.18,    4290.14,    26.8,    5.33,    17.58,    14.29,    248.5,
0.01,    0,    0,    0,    0,    0,    0,    0.151395382,
5.327863403,    5.10096383,    1.32567787,    4.352404124,
0.458606982,    2.915908912,    0.011996374,    0.364710382,
0.033016026,    3.161701212,    0.381564497,    0.010971385,
0.035646472,    0.014781805,    4.129708296,    0.153094117,
0.018497847,    15.09178491,    17.58393041,    14.17643928,
4290.143561,    26.79730719,    294.6367065,    14.2888441,
248.495231,    209.3131795,    2014.506722,    0.010751273,
0.002325138,    0.000637473,    0.003984336,    0.006018154,
0.003620907,    0.0000745936,    0.000142311,    0.002460417,
0.001280189)

Thank you very much for any help you could provide!
regards
Luigi



More information about the R-help mailing list