Hi friends, I have a matrix with following format. group var1 var2 .......varN c1 group1 1.2399 1.4990....-1.4829 c2 group4 0.8989 0.7849.....1.8933 ... ... c100 group10 ..... I want to draw a profile plot of each condition c1 to c100, which rows in above matrix and each line representing a row should be uniquely colored according to the group(1 to 10). I think this is simple task but I could not figure out how to set the colors. Any help would be appreciated. thanks -Vickie [[alternative HTML version deleted]]
On 11-06-17 3:43 PM, Vickie S wrote:> > Hi friends, > > I have a matrix with following format. > > group var1 var2 .......varN > > c1 group1 1.2399 1.4990....-1.4829 > > c2 group4 0.8989 0.7849.....1.8933 > > ... > > ... > > c100 group10 ..... > > > > I want to draw a profile plot > of each condition c1 to c100, which rows in above matrix and each line > representing a row should be uniquely colored according to the group(1 > to 10). > > I think this is simple task but I could not figure out how to set the colors.The matplot function plots matrix columns, so it could do what you want if you transpose your matrix (using t()). It has arguments for colour, line type, etc. that work column-wise. Duncan Murdoch> > > > Any help would be appreciated. > > > > thanks > > -Vickie > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Hi, Another easy option would be to convert your data to "long" format and then use ggplot2 or lattice. Something like (though not exact without a reproducible example): require(ggplot2) long.dat <- melt(your_data, arguments) ggplot(long.dat, aes(x = variable, y = value)) + geom_line(aes(colour = group)) + facet_grid(~ condition) HTH, Josh On Jun 17, 2011, at 12:43, Vickie S <isvik at live.com> wrote:> > Hi friends, > > I have a matrix with following format. > > group var1 var2 .......varN > > c1 group1 1.2399 1.4990....-1.4829 > > c2 group4 0.8989 0.7849.....1.8933 > > ... > > ... > > c100 group10 ..... > > > > I want to draw a profile plot > of each condition c1 to c100, which rows in above matrix and each line > representing a row should be uniquely colored according to the group(1 > to 10). > > I think this is simple task but I could not figure out how to set the colors. > > > > Any help would be appreciated. > > > > thanks > > -Vickie > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Hi thanks for the help. Here is the error message i got. I could not figure out what goes wrong here. =====require(ggplots2) sampledata=data.frame(c(1.002, 1.76, 0.67, 0.99), c(1.38,1.0,0.5, 0.78), c(1.003,0.57,0.99, 0.58),c(0.76,1.23, 1.45, .78), c(1.43, 1.34, 1.0, 0.9)) rownames(sampledata)=c("cond1", "cond2", "cond3", "cond4") colnames(sampledata)=c("col1", "col2", "col3", "col4", "col5") grp=c("grp1", "grp1", "grp2", "grp3") sampledata=cbind(sampledata, grp) long.dat=melt(sampledata[,1:5], idvars=as.character(rownames(sampledata)), measure.vars=as.character(colnames(sampledata)[1:5]), variable_name="cols") ggplot(long.dat, aes(x = cols, y = value)) + +? geom_line(aes(colour = sampledata$grp)) + + facet_grid(~ rownames(sampledata)) Error in get("make_aesthetics", env = x, inherits = TRUE)(x, ...) : ? could not find function "empty" ==== thanks again, Vickie S ----------------------------------------> CC: r-help at r-project.org > From: jwiley.psych at gmail.com > Subject: Re: [R] profile plot in R > Date: Sat, 18 Jun 2011 08:24:01 -0700 > To: isvik at live.com > > Hi, > > Another easy option would be to convert your data to "long" format and then use ggplot2 or lattice. Something like (though not exact without a reproducible example): > > require(ggplot2) > long.dat <- melt(your_data, arguments) > > ggplot(long.dat, aes(x = variable, y = value)) + > geom_line(aes(colour = group)) + > facet_grid(~ condition) > > HTH, > > Josh > > On Jun 17, 2011, at 12:43, Vickie S <isvik at live.com> wrote: > > > > > Hi friends, > > > > I have a matrix with following format. > > > > group var1 var2 .......varN > > > > c1 group1 1.2399 1.4990....-1.4829 > > > > c2 group4 0.8989 0.7849.....1.8933 > > > > ... > > > > ... > > > > c100 group10 ..... > > > > > > > > I want to draw a profile plot > > of each condition c1 to c100, which rows in above matrix and each line > > representing a row should be uniquely colored according to the group(1 > > to 10). > > > > I think this is simple task but I could not figure out how to set the colors. > > > > > > > > Any help would be appreciated. > > > > > > > > thanks > > > > -Vickie > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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.
Hi Dennis and all friends, After upgrading to R 2.11.1, I managed to work this out perfectly. I also added group information here, since I wanted to color code the profiles according to the groups they were assigned to. library("reshape") library("ggplot2") sampledata <- matrix(c(1.002, 1.76, 0.67, 0.99, 1.38, 1.0, 0.5, 0.78, 1.003,0.57, 0.99, 0.58, 0.76, 1.23, 1.45, .78,1.43, 1.34, 1.0, 0.9),ncol = 5, dimnames = list(cond=c("cond1", "cond2","cond3", "cond4"),time = c("col1","col2", "col3", "col4", "col5"))) sdata <- melt(sampledata)?? # melt method for matrices ?grp=c("grp1", "grp1", "grp2", "grp2") ggplot(sdata, aes(time, value, colour=grp)) + ????? geom_point(size = 2.5) + ???? geom_line(aes(group = cond), size = 1) ? Once again many thanks for the help, - Vickie