Hi Folks, I have data that looks like this: freq gender xBar 1000 m 2.32 1000 f 3.22 2000 m 4.32 2000 f 4.53 3000 m 3.21 3000 f 3.44 4000 m 4.11 4000 f 3.99 I want to plot two lines (with symbols) for the two groups "m" and "f". I have tried the following: plot(xBar[gender=="m"]~freq[gender=="f"]) followed by lines(xBar[gender=="m"]~freq[gender=="f"]) with different symbols and lines colors (which I know how to do). However, these initial plots are not giving me the right output. The initial plot command generates the following error. Error in plot.window(xlim, ylim, log, asp, ...) : need finite 'xlim' values In addition: Warning messages: 1: no non-missing arguments to min; returning Inf 2: no non-missing arguments to max; returning -Inf 3: no non-missing arguments to min; returning Inf 4: no non-missing arguments to max; returning -Inf A second issue, I would also like to offset the second set of points along the x-axis so that the error bars will be visible. Any help is appreciated. Regards, Sumit
On 11/4/06, Sumitrajit Dhar <s-dhar at northwestern.edu> wrote:> Hi Folks, > > I have data that looks like this: > > freq gender xBar > 1000 m 2.32 > 1000 f 3.22 > 2000 m 4.32 > 2000 f 4.53 > 3000 m 3.21 > 3000 f 3.44 > 4000 m 4.11 > 4000 f 3.99 > > I want to plot two lines (with symbols) for the two groups "m" and > "f". I have tried the following:This is pretty easy with ggplot. Something like: install.packages("ggplot") library(ggplot) qplot(freq, xBar, data=my.data.frame, colour=gender, id=gender, type=c("point","line")) should do what you want. Hadley
To plot this with classic graphics convert data frame from long to wide format using one of the three alternatives below and then plot: # 1. subset DFm <- subset(DF, gender == "m") DFf <- subset(DF, gender == "f") DFw <- cbind(DFm[1], xBar.m = DFm[,3], xBar.f = DFf[,3]) # 2. reshape DFw <- reshape(DF, dir = "wide", timevar = "gender", idvar = "freq") # 3. cast/melt from the reshape package library(reshape) DFw <- cast(melt(DF, id = 1:2), freq ~ gender) matplot(DFw[,1], DFw[,-1], type = "o", xlab = "freq", ylab = "xBar") Another possibility, not necessitating conversion to wide format, is xyplot in the lattice package: xyplot(xBar ~ freq, DF, group = gender, type = "o", auto.key = TRUE) On 11/4/06, Sumitrajit Dhar <s-dhar at northwestern.edu> wrote:> Hi Folks, > > I have data that looks like this: > > freq gender xBar > 1000 m 2.32 > 1000 f 3.22 > 2000 m 4.32 > 2000 f 4.53 > 3000 m 3.21 > 3000 f 3.44 > 4000 m 4.11 > 4000 f 3.99 > > I want to plot two lines (with symbols) for the two groups "m" and > "f". I have tried the following: > > plot(xBar[gender=="m"]~freq[gender=="f"]) followed by > > lines(xBar[gender=="m"]~freq[gender=="f"]) > > with different symbols and lines colors (which I know how to do). > > However, these initial plots are not giving me the right output. The > initial plot command generates the following error. > Error in plot.window(xlim, ylim, log, asp, ...) : > need finite 'xlim' values > In addition: Warning messages: > 1: no non-missing arguments to min; returning Inf > 2: no non-missing arguments to max; returning -Inf > 3: no non-missing arguments to min; returning Inf > 4: no non-missing arguments to max; returning -Inf > > A second issue, I would also like to offset the second set of points > along the x-axis so that the error bars will be visible. > > Any help is appreciated. > > Regards, > Sumit > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
At 04:06 05/11/2006, Sumitrajit Dhar wrote:>Hi Folks, > >I have data that looks like this: > >freq gender xBar >1000 m 2.32 >1000 f 3.22 >2000 m 4.32 >2000 f 4.53 >3000 m 3.21 >3000 f 3.44 >4000 m 4.11 >4000 f 3.99 > >I want to plot two lines (with symbols) for the two groups "m" and >"f". I have tried the following: > >plot(xBar[gender=="m"]~freq[gender=="f"]) followed bySo you want to plot the value of xBar for a man against the corresponding freq for a woman? But how are we to tell which man maps to which woman?>lines(xBar[gender=="m"]~freq[gender=="f"]) > >with different symbols and lines colors (which I know how to do). > >However, these initial plots are not giving me the right output. The >initial plot command generates the following error. >Error in plot.window(xlim, ylim, log, asp, ...) : > need finite 'xlim' values >In addition: Warning messages: >1: no non-missing arguments to min; returning Inf >2: no non-missing arguments to max; returning -Inf >3: no non-missing arguments to min; returning Inf >4: no non-missing arguments to max; returning -Inf > >A second issue, I would also like to offset the second set of points >along the x-axis so that the error bars will be visible. > >Any help is appreciated. > >Regards, >Sumit > >Michael Dewey http://www.aghmed.fsnet.co.uk