I am looking for a way to produce a "distribution graph" as in the example: (http://cecsweb.dartmouth.edu/release1.1/datatools/dgraph.php?year=2003&geotype=STD_HRR&event=A01_DIS&eventtype=UTIL Anybody who can help? Christian von Plessen Department of Pulmonary Medicine Haukeland university hospital Bergen Norway
?violinplot (You need to install the UsingR package first.) On Mar 23, 2007, at 4:06 AM, Plessen, Christian von wrote:> I am looking for a way to produce a "distribution graph" as in the > example: > > (http://cecsweb.dartmouth.edu/release1.1/datatools/dgraph.php? > year=2003&geotype=STD_HRR&event=A01_DIS&eventtype=UTIL > > Anybody who can help?
[Apologies -- there were errors in the code I posted previously. A corrected version is below] On 23-Mar-07 11:06:49, Plessen, Christian von wrote:> > I am looking for a way to produce a "distribution graph" as in the > example: > > (http://cecsweb.dartmouth.edu/release1.1/datatools/dgraph.php?year=2003& > geotype=STD_HRR&event=A01_DIS&eventtype=UTIL > > Anybody who can help? > > Christian von Plessen > Department of Pulmonary Medicine > Haukeland university hospital > Bergen > NorwayThe following (which anyway needs refinement, and can very probably be done better) provides a basis (illustrated using a sample from a log-normal distribution): X<-exp(rnorm(200,sd=0.25)+2)/5 H<-hist(X,breaks=20) C<-H$counts Y<-H$mids C1<-C/2 C0<-(-(C1[1]-1/2)):(C1[1]-1/2); n0<-length(C0) plot(C0,rep(Y[1],n0),xlim=c(-max(C)/2,max(C)/2),ylim=c(min(Y),max(Y))) for(i in (2:length(Y))){ if(C[i]==0) next C0 <- (-(C1[i] - 1/2)):(C1[i] - 1/2); n0<-length(C0) points(C0,rep(Y[i],n0)) } Hoping this helps! Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 23-Mar-07 Time: 13:04:51 ------------------------------ XFMail ------------------------------ -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 23-Mar-07 Time: 14:22:50 ------------------------------ XFMail ------------------------------
On Fri, 2007-03-23 at 14:22 +0000, ted.harding at nessie.mcc.ac.uk wrote:> [Apologies -- there were errors in the code I posted previously. > A corrected version is below] > > On 23-Mar-07 11:06:49, Plessen, Christian von wrote: > > > > I am looking for a way to produce a "distribution graph" as in the > > example: > > > > (http://cecsweb.dartmouth.edu/release1.1/datatools/dgraph.php?year=2003& > > geotype=STD_HRR&event=A01_DIS&eventtype=UTIL > > > > Anybody who can help? > > > > The following (which anyway needs refinement, and can very > probably be done better) provides a basis (illustrated using > a sample from a log-normal distribution): > > > X<-exp(rnorm(200,sd=0.25)+2)/5 > > H<-hist(X,breaks=20) > C<-H$counts > Y<-H$mids > C1<-C/2 > > C0<-(-(C1[1]-1/2)):(C1[1]-1/2); n0<-length(C0) > plot(C0,rep(Y[1],n0),xlim=c(-max(C)/2,max(C)/2),ylim=c(min(Y),max(Y))) > > for(i in (2:length(Y))){ > if(C[i]==0) next > C0 <- (-(C1[i] - 1/2)):(C1[i] - 1/2); n0<-length(C0) > points(C0,rep(Y[i],n0)) > } > > > Hoping this helps! > Ted.How about something like this: DistPlot <- function(x, digits = 1, ...) { x <- round(x, digits) Tab <- table(x) Vals <- sapply(Tab, function(x) seq(x) - mean(seq(x))) X.Vals <- unlist(Vals, use.names = FALSE) tmp <- sapply(Vals, length) Y.Vals <- rep(names(tmp), tmp) plot(X.Vals, Y.Vals, ...) } Vec <- exp(rnorm(200, sd = 0.25) + 2) / 5 DistPlot(Vec, pch = 19) HTH, Marc Schwartz