HI everyone, I'm just starting to get into graphing with R and I need to generate one graph that illustrates the pattern of gene expression for various patients. My data is in .csv format and is as follows and i'm showing below a portion of the data. Pt Coordinate Log2Ratio 1 34046382 -0.023639869 1 34141437 0.016456776 1 34232498 -0.027852121 1 34261900 -0.167065347 2 34364856 -0.182864057 2 34461485 -0.228341688 2 34952694 1.90875531 3 34174705 1.312169128 3 34247833 1.381729262 3 34320273 1.218914649 3 34390545 0.992551194 I can generate the multiple line graphs but i can't get the different colors per patient, nor do i know how to change the pattern of the line. Any ideas and help is greatly appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Multiple-line-graphs-tp3652015p3652015.html Sent from the R help mailing list archive at Nabble.com.
Hi lt2, I would use the ggplot2 or lattice package. It strikes me as more effort to do in traditional graphics. Anyway, here are some examples. Lattice is a very nice package, but I am not quite as familiar with it, so my examples for it are not representative of its full power. Cheers, Josh #################### # Your data dat <- read.table(textConnection(" Pt Coordinate Log2Ratio 1 34046382 -0.023639869 1 34141437 0.016456776 1 34232498 -0.027852121 1 34261900 -0.167065347 2 34364856 -0.182864057 2 34461485 -0.228341688 2 34952694 1.90875531 3 34174705 1.312169128 3 34247833 1.381729262 3 34320273 1.218914649 3 34390545 0.992551194"), header = TRUE) closeAllConnections() require(ggplot2) require(lattice) #### Solution using the ggplot2 package #### ## Using colours by patient ggplot(dat, aes(x = Coordinate, y = Log2Ratio, colour = factor(Pt))) + geom_line() ## Mapping Pt to type of line ggplot(dat, aes(x = Coordinate, y = Log2Ratio)) + geom_line(aes(linetype = factor(Pt))) ## Nothing, but creating separate plots ggplot(dat, aes(x = Coordinate, y = Log2Ratio)) + geom_line() + facet_grid(Pt ~ .) #### Solution using the lattice package #### ## Colouring lines xyplot(Log2Ratio ~ Coordinate, data = dat, group = Pt, type = "l", auto.key = list(points = FALSE, lines = TRUE)) ## Condition on lines xyplot(Log2Ratio ~ Coordinate | factor(Pt), data = dat, type = "l") On Thu, Jul 7, 2011 at 9:38 AM, lt2 <lt2 at bcm.edu> wrote:> HI everyone, I'm just starting to get into graphing with R and I need to > generate one graph that illustrates the pattern of gene expression for > various patients. My data is in .csv format and is as follows and i'm > showing below a portion of the data. > > Pt ? ? ?Coordinate ? ? ?Log2Ratio > 1 ? ? ? 34046382 ? ? ? ?-0.023639869 > 1 ? ? ? 34141437 ? ? ? ?0.016456776 > 1 ? ? ? 34232498 ? ? ? ?-0.027852121 > 1 ? ? ? 34261900 ? ? ? ?-0.167065347 > 2 ? ? ? 34364856 ? ? ? ?-0.182864057 > 2 ? ? ? 34461485 ? ? ? ?-0.228341688 > 2 ? ? ? 34952694 ? ? ? ?1.90875531 > 3 ? ? ? 34174705 ? ? ? ?1.312169128 > 3 ? ? ? 34247833 ? ? ? ?1.381729262 > 3 ? ? ? 34320273 ? ? ? ?1.218914649 > 3 ? ? ? 34390545 ? ? ? ?0.992551194 > > I can generate the multiple line graphs but i can't get the different colors > per patient, nor do i know how to change the pattern of the line. > > Any ideas and help is greatly appreciated. > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Multiple-line-graphs-tp3652015p3652015.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/
Thank you!!!!! LT On 7/7/11 3:46 PM, "Joshua Wiley" <jwiley.psych@gmail.com> wrote: Hi lt2, I would use the ggplot2 or lattice package. It strikes me as more effort to do in traditional graphics. Anyway, here are some examples. Lattice is a very nice package, but I am not quite as familiar with it, so my examples for it are not representative of its full power. Cheers, Josh #################### # Your data dat <- read.table(textConnection(" Pt Coordinate Log2Ratio 1 34046382 -0.023639869 1 34141437 0.016456776 1 34232498 -0.027852121 1 34261900 -0.167065347 2 34364856 -0.182864057 2 34461485 -0.228341688 2 34952694 1.90875531 3 34174705 1.312169128 3 34247833 1.381729262 3 34320273 1.218914649 3 34390545 0.992551194"), header = TRUE) closeAllConnections() require(ggplot2) require(lattice) #### Solution using the ggplot2 package #### ## Using colours by patient ggplot(dat, aes(x = Coordinate, y = Log2Ratio, colour = factor(Pt))) + geom_line() ## Mapping Pt to type of line ggplot(dat, aes(x = Coordinate, y = Log2Ratio)) + geom_line(aes(linetype = factor(Pt))) ## Nothing, but creating separate plots ggplot(dat, aes(x = Coordinate, y = Log2Ratio)) + geom_line() + facet_grid(Pt ~ .) #### Solution using the lattice package #### ## Colouring lines xyplot(Log2Ratio ~ Coordinate, data = dat, group = Pt, type = "l", auto.key = list(points = FALSE, lines = TRUE)) ## Condition on lines xyplot(Log2Ratio ~ Coordinate | factor(Pt), data = dat, type = "l") On Thu, Jul 7, 2011 at 9:38 AM, lt2 <lt2@bcm.edu> wrote:> HI everyone, I''m just starting to get into graphing with R and I need to > generate one graph that illustrates the pattern of gene expression for > various patients. My data is in .csv format and is as follows and i''m > showing below a portion of the data. > > Pt Coordinate Log2Ratio > 1 34046382 -0.023639869 > 1 34141437 0.016456776 > 1 34232498 -0.027852121 > 1 34261900 -0.167065347 > 2 34364856 -0.182864057 > 2 34461485 -0.228341688 > 2 34952694 1.90875531 > 3 34174705 1.312169128 > 3 34247833 1.381729262 > 3 34320273 1.218914649 > 3 34390545 0.992551194 > > I can generate the multiple line graphs but i can''t get the different colors > per patient, nor do i know how to change the pattern of the line. > > Any ideas and help is greatly appreciated. > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Multiple-line-graphs-tp3652015p3652015.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/ [[alternative HTML version deleted]]