[R] ask for help xyplot

Daniel Malter daniel at umd.edu
Wed Jun 24 01:21:06 CEST 2009


Aimin, please provide self-contained code. This is not "data" but a printed
table. Next time, provide real or simulated data in a way that it can be
copied directly into R or an R editor. Also, it is quite impossible to tell
from your question how you want to plot it. The grouping is not the problem,
but what do you mean by "plot Mean with SD(+/-)." How should it look like?
Also, some SDs are NAs. What to do about them?

Here is my guess for what I think you might want to do. Pay special
attention to the tapply commands that compute mean MEANS and mean SDs for
each LACxDIM bin. Also pay special attention to how you have to recode the
DIM and LAC variables (here recoded into DIM2 and LAC2) to plot the MEAN and
SDs with the right DIM and LAC indicator.

#Simulate data
DIM=rep(1:4,each=10)
LAC=rep(1:5,8)
MEAN=rnorm(40,45,10)
SD=rgamma(40,15,2)

#Summary for DIMxLAC bins
tapply(MEAN,list(DIM,LAC),mean)

#the same in one vector
#pay attention how they are ordered
c(tapply(MEAN,list(DIM,LAC),mean))


MEAN2=c(tapply(MEAN,list(DIM,LAC),mean))
SD2=c(tapply(SD,list(DIM,LAC),mean))
INT.plus=MEAN2+SD2
INT.minus=MEAN2-SD2

#recode LAC2 and DIM2 accordingly
#to match the order in MEAN2 and SD2
LAC2=rep(1:5,each=4)
DIM2=rep(1:4,5)

#plot
#may require to install package Hmisc
library(Hmisc)
Dotplot(LAC2~Cbind(MEAN2,INT.minus,INT.plus)|DIM2,method="bars")

hth
Daniel
-------------------------
cuncta stricte discussurus
-------------------------

-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von jlfmssm
Gesendet: Tuesday, June 23, 2009 6:07 PM
An: r-help at r-project.org
Betreff: [R] ask for help xyplot

I want to make such plot using the following data set

plot Mean with Sd(+/-) by Dim group by Lac

here is data

Does anyone know how to plot using xyploy

Thanks,

Aimin

        Mean         Sd          Var   Min   Max Dim Lac
704  44.00000         NA           NA  44.0  44.0 -30   3
703  45.92000  9.5484030   91.1720000  60.0  34.4 -30   4
702  57.40000         NA           NA  57.4  57.4 -30   5
707  49.00000         NA           NA  49.0  49.0 -29   3
706  43.12000 16.5762481  274.7720000  61.0  16.8 -29   4
705  60.40000         NA           NA  60.4  60.4 -29   5
710  32.65000 21.2987480  453.6366667  52.0   8.4 -28   3
709  36.30000 13.2717746  176.1400000  51.2  22.2 -28   4
708  39.60000         NA           NA  39.6  39.6 -28   6
713  43.84000 16.3226223  266.4280000  57.4  15.8 -27   3
712  39.46667 10.7930842  116.4906667  50.2  24.8 -27   4
711  23.40000         NA           NA  23.4  23.4 -27   6
717  36.86667 16.5373113  273.4826667  52.0  11.0 -26   3
716  51.77143 21.5293377  463.5123810  93.0  20.2 -26   4
715  56.20000         NA           NA  56.2  56.2 -26   5
714  38.00000         NA           NA  38.0  38.0 -26   6
628  33.33333 22.0927741  488.0906667  60.6   0.6 -25   3
627  46.20000 11.9002521  141.6160000  55.0  22.8 -25   4
626  45.00000 16.1220346  259.9200000  56.4  33.6 -25   5
738  36.76000 16.8014285  282.2880000  49.8   9.4 -24   3
737  45.05000 17.6313168  310.8633333  61.2  21.6 -24   4
736  53.70000  2.1213203    4.5000000  55.2  52.2 -24   5
122  38.14286 17.1455395  293.9695238  58.0   8.0 -23   3
121  49.36667 18.7456306  351.3986667  69.2  15.6 -23   4
120  50.25000  9.2885234   86.2766667  58.8  37.8 -23   5
119  80.00000         NA           NA  80.0  80.0 -23   6
126  47.37778  5.8072751   33.7244444  55.2  37.8 -22   3
125  59.10000 18.5004865  342.2680000  87.6  40.8 -22   4
124  57.44000 24.3065423  590.8080000  99.0  38.6 -22   5
123  30.40000         NA           NA  30.4  30.4 -22   7
129  50.00000 13.8258557  191.1542857  78.0  30.0 -21   3
128  40.92000 20.8502278  434.7320000  62.8   7.0 -21   4
127  49.80000  1.0392305    1.0800000  50.4  48.6 -21   5
721  52.20000  6.2369865   38.9000000  61.2  43.2 -20   3
720  49.36000  6.7740682   45.8880000  56.8  42.2 -20   4

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list