Christopher W. Ryan
2008-Jun-26 19:18 UTC
[R] stuck on making a line graph across time, with 4 categories
I can't seem to find just what I'm looking for in R help, Everitt and Hothorn HSAUR, Murrell's book, or the R graphics gallery at http://addictedtor.free.fr/graphiques/. Probably not looking efficiently, but anyway, If my data look like this:> head(data)cat startyear studentid 1 other 2001 12 2 UHS 2001 17 3 Lourdes 2001 10 4 Endwell 2001 3 5 other 2002 13 6 UHS 2002 19>What is the easiest way to make a line graph like this (made this one in Stata): http://bingweb.binghamton.edu/~cryan/Workload.png Thank you. --Chris -- Christopher W. Ryan, MD SUNY Upstate Medical University Clinical Campus at Binghamton 40 Arch Street, Johnson City, NY 13790 cryanatbinghamtondotedu PGP public keys available at http://home.stny.rr.com/ryancw/ "If you want to build a ship, don't drum up the men to gather wood, divide the work and give orders. Instead, teach them to yearn for the vast and endless sea." [Antoine de St. Exupery]
Ben Bolker
2008-Jun-26 19:22 UTC
[R] stuck on making a line graph across time, with 4 categories
Christopher W. Ryan <cryan <at> binghamton.edu> writes:> > I can't seem to find just what I'm looking for in R help, Everitt and > Hothorn HSAUR, Murrell's book, or the R graphics gallery at > http://addictedtor.free.fr/graphiques/. Probably not looking > efficiently, but anyway, > > If my data look like this: > > > head(data) > cat startyear studentid > 1 other 2001 12 > 2 UHS 2001 17 > 3 Lourdes 2001 10 > 4 Endwell 2001 3 > 5 other 2002 13 > 6 UHS 2002 19 > > > > What is the easiest way to make a line graph like this (made this one in > Stata): > > http://bingweb.binghamton.edu/~cryan/Workload.png > > Thank you.assuming "studentid" is your students, library(lattice) xyplot(studentid~startyear,groups=cat,auto.key=TRUE,type="l",data=data) (I think -- haven't tested at all) that, or reshape the data to wide format and use matplot. Ben Bolker
ONKELINX, Thierry
2008-Jun-27 08:59 UTC
[R] stuck on making a line graph across time, with 4 categories
A solution with ggplot2 would be dataset <- data.frame(cat = factor(rbinom(1000, 1, prob = .33), labels LETTERS[1:2]), startyear = floor(runif(1000, 2001, 2009)), studentid 1:1000) library(ggplot2) ggplot(dataset, aes(x = startyear, colour = cat)) + stat_bin(aes(y ..count..), geom="line", breaks = 2000:2008 + 0.5) HTH, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx op inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -----Oorspronkelijk bericht----- Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org] Namens Christopher W. Ryan Verzonden: donderdag 26 juni 2008 21:18 Aan: r-help op stat.math.ethz.ch Onderwerp: [R] stuck on making a line graph across time, with 4 categories I can't seem to find just what I'm looking for in R help, Everitt and Hothorn HSAUR, Murrell's book, or the R graphics gallery at http://addictedtor.free.fr/graphiques/. Probably not looking efficiently, but anyway, If my data look like this:> head(data)cat startyear studentid 1 other 2001 12 2 UHS 2001 17 3 Lourdes 2001 10 4 Endwell 2001 3 5 other 2002 13 6 UHS 2002 19>What is the easiest way to make a line graph like this (made this one in Stata): http://bingweb.binghamton.edu/~cryan/Workload.png Thank you. --Chris -- Christopher W. Ryan, MD SUNY Upstate Medical University Clinical Campus at Binghamton 40 Arch Street, Johnson City, NY 13790 cryanatbinghamtondotedu PGP public keys available at http://home.stny.rr.com/ryancw/ "If you want to build a ship, don't drum up the men to gather wood, divide the work and give orders. Instead, teach them to yearn for the vast and endless sea." [Antoine de St. Exupery] ______________________________________________ R-help op 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.
Reasonably Related Threads
- problem using identify() after plot()
- having trouble extracting week from chron object
- automatic exploration of all possible loglinear models?
- How would I color points conditional on their value in a plot of a time series
- How would I color points conditional on their value in a plot of a time series