I have a matrix like this Name 1 2 3 4 5 NM_001039514 1.033557047 0.7469879518 0.9004524887 0.8613861386 0.7952499048 NM_001039723 1.0759493671 1.2315789474 0.8666666667 1.1142857143 0.9428011471 NM_001042605 0.9897435897 0.8870431894 1.1038062284 0.7407407407 0.744530664 NM_001048207 1.0070422535 0.9319727891 0.9015151515 0.8296438884 0.7290217712 I want to plot each row in a single graph and then use multiplot to put them all together in a single graph. How do you plot the rows? -- View this message in context: http://r.789695.n4.nabble.com/ggplot-simple-question-tp4628640.html Sent from the R help mailing list archive at Nabble.com.
ggplot simple question.
3 messages · rmje, John Kane, Jeff Newmiller
That does not look like a matrix but a data frame. Do a class(dataname) to check. It is much better to present the data in a useable format. Have a look at ?dput for a way to provide the data. However if we assulme your data is xx, this may do what you want if I understand you correcctly. xx1 <-data.frame( t(xx[, 2:6])) xx1[,5] <- names(xx[2:6]) names(xx1) <- c(letters[1:4], "Name") ggplot(xx1, aes(x=factor(Name), a)) + geom_point() John Kane Kingston ON Canada
-----Original Message----- From: robinmjelle at gmail.com Sent: Sat, 12 May 2012 03:29:35 -0700 (PDT) To: r-help at r-project.org Subject: [R] ggplot simple question. I have a matrix like this Name 1 2 3 4 5 NM_001039514 1.033557047 0.7469879518 0.9004524887 0.8613861386 0.7952499048 NM_001039723 1.0759493671 1.2315789474 0.8666666667 1.1142857143 0.9428011471 NM_001042605 0.9897435897 0.8870431894 1.1038062284 0.7407407407 0.744530664 NM_001048207 1.0070422535 0.9319727891 0.9015151515 0.8296438884 0.7290217712 I want to plot each row in a single graph and then use multiplot to put them all together in a single graph. How do you plot the rows? -- View this message in context: http://r.789695.n4.nabble.com/ggplot-simple-question-tp4628640.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.
____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
On Sat, 12 May 2012, rmje wrote:
I have a matrix like this Name 1 2 3 4 5 NM_001039514 1.033557047 0.7469879518 0.9004524887 0.8613861386 0.7952499048 NM_001039723 1.0759493671 1.2315789474 0.8666666667 1.1142857143 0.9428011471 NM_001042605 0.9897435897 0.8870431894 1.1038062284 0.7407407407 0.744530664 NM_001048207 1.0070422535 0.9319727891 0.9015151515 0.8296438884 0.7290217712 I want to plot each row in a single graph and then use multiplot to put them all together in a single graph. How do you plot the rows?
Please use dput() to generate R commands to recreate your sample data.
For example, I type "dta <- " and then copy-paste the output of dput(dta):
dta <- structure(list(Name = structure(1:4, .Label = c("NM_001039514",
"NM_001039723", "NM_001042605", "NM_001048207"), class = "factor"),
X1 = c(1.033557047, 1.0759493671, 0.9897435897, 1.0070422535
), X2 = c(0.7469879518, 1.2315789474, 0.8870431894, 0.9319727891
), X3 = c(0.9004524887, 0.8666666667, 1.1038062284, 0.9015151515
), X4 = c(0.8613861386, 1.1142857143, 0.7407407407, 0.8296438884
), X5 = c(0.7952499048, 0.9428011471, 0.744530664, 0.7290217712
)), .Names = c("Name", "X1", "X2", "X3", "X4", "X5"), class =
"data.frame", row.names = c(NA,
-4L))
You have stated that this is a matrix, but it obviously contains text for
row names. The standard output of write.table doesn't put a heading above
row names, so this looks more like a data frame. I don't know how your row
names were set up as numerics... when I used read.table() to pull your
example in, the headings were changed to valid data frame column names by
prepending "X". Your use of dput() would have made all thes questions
irrelevant.
AFAIK all plotting in R assumes data series are vectors or columns, not
rows, so some data structure transformation is needed before your
desired plots can be generated.
There is probably more than one way to skin this cat, but here is one way:
library(reshape2)
library(ggplot2)
dtalong <- melt( dta, "Name" )
dtalong$x <- as.numeric( substring( as.character( dtalong$variable ), 2 ) )
ggplot( dtalong, aes( x=x, y=value ) ) +
geom_point() +
facet_wrap( ~Name, ncol=1 )
If you are not familiar with melt, use ?melt to read the help and
experiment with it, and use the str() function to study dta and dtalong
to see how the data are moved around.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k