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 -------------- next part -------------- time class value 1 18 medium 2.92 2 18 medium 0.01 3 18 medium 0.36 4 18 medium 3.16 5 18 medium 0.99 6 18 medium 0.38 7 18 medium 0.01 8 18 medium 5.1 9 18 medium 0.04 10 18 medium 0.01 11 18 medium 1.33 12 18 medium 4.13 13 18 medium 0.15 14 18 medium 0.15 15 18 high 14.18 16 18 high "4,290.14" 17 18 high 26.8 18 18 high 5.33 19 18 high 17.58 20 18 high 14.29 21 18 high 248.5 22 18 low 0.01 23 18 low 0 24 18 low 0 25 18 low 0 26 18 low 0 27 18 low 0 28 18 low 0 29 12 medium 0.151395382 30 12 medium 5.327863403 31 12 medium 5.10096383 32 12 medium 1.32567787 33 12 medium 4.352404124 34 12 medium 0.458606982 35 12 medium 2.915908912 36 12 medium 0.011996374 37 12 medium 0.364710382 38 12 medium 0.033016026 39 12 medium 3.161701212 40 12 medium 0.381564497 41 12 medium 0.010971385 42 12 medium 0.035646472 43 12 medium 0.014781805 44 12 medium 4.129708296 45 12 medium 0.153094117 46 12 medium 0.018497847 47 12 high 15.09178491 48 12 high 17.58393041 49 12 high 14.17643928 50 12 high 4290.143561 51 12 high 26.79730719 52 12 high 294.6367065 53 12 high 14.2888441 54 12 high 248.495231 55 12 high 209.3131795 56 12 high 2014.506722 57 12 low 0.010751273 58 12 low 0.002325138 59 12 low 0.000637473 60 12 low 0.003984336 61 12 low 0.006018154 62 12 low 0.003620907 63 12 low 7.46E-05 64 12 low 0.000142311 65 12 low 0.002460417 66 12 low 0.001280189
On 12/19/2013 11:18 AM, Luigi Marongiu wrote:> 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.Hi Luigi, Perhaps you want something like this: lmdf<-read.table(text="time class value 18 medium 2.92 18 medium 0.01 18 medium 0.36 18 medium 3.16 18 medium 0.99 18 medium 0.38 18 medium 0.01 18 medium 5.1 18 medium 0.04 18 medium 0.01 18 medium 1.33 18 medium 4.13 18 medium 0.15 18 medium 0.15 18 high 14.18 18 high 4290.14 18 high 26.8 18 high 5.33 18 high 17.58 18 high 14.29 18 high 248.5 18 low 0.01 18 low 0 18 low 0 18 low 0 18 low 0 18 low 0 18 low 0 12 medium 0.151395382 12 medium 5.327863403 12 medium 5.10096383 12 medium 1.32567787 12 medium 4.352404124 12 medium 0.458606982 12 medium 2.915908912 12 medium 0.011996374 12 medium 0.364710382 12 medium 0.033016026 12 medium 3.161701212 12 medium 0.381564497 12 medium 0.010971385 12 medium 0.035646472 12 medium 0.014781805 12 medium 4.129708296 12 medium 0.153094117 12 medium 0.018497847 12 high 15.09178491 12 high 17.58393041 12 high 14.17643928 12 high 4290.143561 12 high 26.79730719 12 high 294.6367065 12 high 14.2888441 12 high 248.495231 12 high 209.3131795 12 high 2014.506722 12 low 0.010751273 12 low 0.002325138 12 low 0.000637473 12 low 0.003984336 12 low 0.006018154 12 low 0.003620907 12 low 7.46E-05 12 low 0.000142311 12 low 0.002460417 12 low 0.001280189",header=TRUE) # get the factor levels in the correct order lmdf$class<-factor(lmdf$class,levels=c("low","medium","high")) library(plotrix) brkdn.plot("value","class","time",lmdf,col=2:4) legend(14,1200,c("low","medium","high"),col=2:4,lty=1) Jim
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