Dear R help-list reader, I would like to generate a plot which compares to states in a patient treatment, before and after. for this reason I have generated a vector before<-c(1,30,23,40) and after<-c(20,10,20,60) the first element in "before" corresponds to the first element in "after". I would like and generate a dotplot with before and after as x-scale, the elements of "before" and "after" on the y-scale and the corresponding elements connected with a line. However, so far I couldn't figure out how to do this in R. If anyone as a suggestion, please let me know Many thanks Frank -- Frank Mattes, MD e-mail: f.mattes at ucl.ac.uk Department of Virology fax 0044(0)207 8302854 Royal Free Hospital and tel 0044(0)207 8302997 University College Medical School London
On Wed, 2003-05-28 at 11:48, Frank Mattes wrote:> Dear R help-list reader, > > I would like to generate a plot which compares to states in a patient > treatment, before and after. for this reason I have generated a vector > before<-c(1,30,23,40) > and > after<-c(20,10,20,60) > the first element in "before" corresponds to the first element in "after". > I would like and generate a dotplot with > before and after as x-scale, the elements of "before" and "after" on > the y-scale and the corresponding elements connected with a line. > > However, so far I couldn't figure out how to do this in R. If anyone > as a suggestion, please let me know > > Many thanks > > FrankDr. Mattes, How about this, using interaction.plot() in package nlme (I am presuming that each pair of measures is an independent pairing). It takes a bit to get the data in the proper structure, but the plotting is then easy: before <- c(1,30,23,40) after <- c(20,10,20,60) # Create a new dataframe with columns: # 'score', 'when' and 'unit' # 'when' and 'unit' are set to factors before.new <- data.frame(score = before, when = "Before", unit = factor(1:4)) after.new <- data.frame(score = after, when = "After", unit = factor(1:4)) df.new <- rbind(before.new, after.new) #display df.new to see the structure df.new # load nlme library(nlme) #attach the dataframe to call variables directly attach(df.new) #create plot interaction.plot(when, unit, score, ylab = "Score", xlab = "When", col = rainbow(4)) # detach df.new to clean up detach(df.new) See ?interaction.plot for more information. This is a simple example of the function which can handle repeated measures (the default y axis is the means of scores) and multiple x-axis factors (for example if you had before, 1 wk after and 2 wks after). HTH, Marc Schwartz
Thomas W Blackwell
2003-May-28 18:47 UTC
[R] how to get a line plot before/after treatment
Frank - Roughly speaking: matplot(c(0,10), rbind(before, after), type="l", axes=F, xlab="time", ylab="measurement") axis(2) axis(1, c(0,10), c("before","after")) Should do the job, if I interpret correctly the plot you have in mind. See help("matplot") : Details, and many pages of help("par") for ways to modify and decorate the basic plot. - tom blackwell - u michigan medical school - ann arbor - On Wed, 28 May 2003, Frank Mattes wrote:> Dear R help-list reader, > > I would like to generate a plot which compares to states in a patient > treatment, before and after. for this reason I have generated a vector > before<-c(1,30,23,40) > and > after<-c(20,10,20,60) > the first element in "before" corresponds to the first element in "after". > I would like and generate a dotplot with > before and after as x-scale, the elements of "before" and "after" on > the y-scale and the corresponding elements connected with a line. > > However, so far I couldn't figure out how to do this in R. If anyone > as a suggestion, please let me know > > Many thanks > > Frank > -- > Frank Mattes, MD e-mail: f.mattes at ucl.ac.uk > Department of Virology fax 0044(0)207 8302854 > Royal Free Hospital and tel 0044(0)207 8302997 > University College Medical School > London > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >