Dear mailing list members, I am a new R user, I would like to plot the follewing data var1 <- c(1,2,1,1,2,1,2,1,2,2) var2 <- round(rgamma(10,2,1)/0.1)*0.1 var3 <- c(0,1,0,1,0,0,0,0,1,0) var4 <- c(1,2,2,2,1,1,1,1,1,1) Var <- data.frame(var1,var2,var3,var4) Var <- Var[sort(Var$var1),] tt <- Var$var1+((runif(length(Var$var1))/6)-(0.5/6)) labelname <- c("time 1", "time 2") plot(tt,var2,xaxt = "n") axis(1,1:length(unique(var1)), labelname) Could you tell me please how can I get diffrent colour and plotting symbols according to var3 and var4, respectively. Diego! ____________________________________________________________________________________ Looking for last minute shopping deals? [[alternative HTML version deleted]]
Henrique Dallazuanna
2008-Mar-19 14:52 UTC
[R] plot with diffrent colour and plotting symbols
Perhaps: cols <- colors()[1:length(unique(apply(Var[3:4], 1, paste, collapse="")))*50] plot(tt, var2, type='p', col=cols, pch=16) On 19/03/2008, Diego Culattoni <diegoculattoni at yahoo.com> wrote:> Dear mailing list members, > > I am a new R user, I would like to plot the follewing data > > var1 <- c(1,2,1,1,2,1,2,1,2,2) > var2 <- round(rgamma(10,2,1)/0.1)*0.1 > var3 <- c(0,1,0,1,0,0,0,0,1,0) > var4 <- c(1,2,2,2,1,1,1,1,1,1) > > Var <- data.frame(var1,var2,var3,var4) > Var <- Var[sort(Var$var1),]I think is this what you want: Var <- Var[order(Var$var1),]> tt <- Var$var1+((runif(length(Var$var1))/6)-(0.5/6)) > labelname <- c("time 1", "time 2") > > plot(tt,var2,xaxt = "n") > axis(1,1:length(unique(var1)), labelname) > > Could you tell me please how can I get diffrent colour and plotting symbols according to var3 and var4, respectively. > > Diego! > > > ____________________________________________________________________________________ > Looking for last minute shopping deals? > > [[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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Hi r-help-bounces at r-project.org napsal dne 19.03.2008 14:18:39:> Dear mailing list members, > > I am a new R user, I would like to plot the follewing data > > var1 <- c(1,2,1,1,2,1,2,1,2,2) > var2 <- round(rgamma(10,2,1)/0.1)*0.1 > var3 <- c(0,1,0,1,0,0,0,0,1,0) > var4 <- c(1,2,2,2,1,1,1,1,1,1) > > Var <- data.frame(var1,var2,var3,var4) > Var <- Var[sort(Var$var1),] > tt <- Var$var1+((runif(length(Var$var1))/6)-(0.5/6)) > labelname <- c("time 1", "time 2") > > plot(tt,var2,xaxt = "n") > axis(1,1:length(unique(var1)), labelname) > > Could you tell me please how can I get diffrent colour and plottingsymbols> according to var3 and var4, respectively.Like plot(tt,var2,xaxt = "n", pch=var3+1, col=var4) see ?par for customising plot parameters. Beware also that var3 is a vector and also a part of your Var data frame which is sorted differently. So this direct call to var3 and var4 reference var3 and var4 vectors not columns from data frame. Regards Petr> > Diego! > > > >____________________________________________________________________________________> Looking for last minute shopping deals? > > [[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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Thank you very much! What I would like to have at the end a cols <- c(1,2,3,4), so cols = 1 if var3=0 and var4=1 cols = 2 and pchs=1 if var3=0 and var4=1 cols = 3 if var3=0 and var4=2 cols = 4 and pchs=1 if var3=0 and var4=2 Can this be down similarly? Thanks in advance, Diego ----- Original Message ---- From: Henrique Dallazuanna <wwwhsd@gmail.com> To: Diego Culattoni <diegoculattoni@yahoo.com> Cc: r-help@stat.math.ethz.ch Sent: Wednesday, March 19, 2008 3:52:06 PM Subject: Re: [R] plot with diffrent colour and plotting symbols Perhaps: cols <- colors()[1:length(unique(apply(Var[3:4], 1, paste, collapse="")))*50] plot(tt, var2, type='p', col=cols, pch=16) On 19/03/2008, Diego Culattoni <diegoculattoni@yahoo.com> wrote:> Dear mailing list members, > > I am a new R user, I would like to plot the follewing data > > var1 <- c(1,2,1,1,2,1,2,1,2,2) > var2 <- round(rgamma(10,2,1)/0.1)*0.1 > var3 <- c(0,1,0,1,0,0,0,0,1,0) > var4 <- c(1,2,2,2,1,1,1,1,1,1) > > Var <- data.frame(var1,var2,var3,var4) > Var <- Var[sort(Var$var1),]I think is this what you want: Var <- Var[order(Var$var1),]> tt <- Var$var1+((runif(length(Var$var1))/6)-(0.5/6)) > labelname <- c("time 1", "time 2") > > plot(tt,var2,xaxt = "n") > axis(1,1:length(unique(var1)), labelname) > > Could you tell me please how can I get diffrent colour and plotting symbols according to var3 and var4, respectively. > > Diego! > > > ____________________________________________________________________________________ > Looking for last minute shopping deals? > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ____________________________________________________________________________________ http://www.yahoo..com/r/hs [[alternative HTML version deleted]]
?points Does this do what you wanted? ------------------------------------------------- plot(tt, var2,xaxt ="n", ylim=c(min(Var[1:3]), max(Var[1:3]))) axis(1,1:length(unique(var1)), labelname) points(tt, var3, col="green") points(tt,var4, col= "red") --------------------------------------------------- --- Diego Culattoni <diegoculattoni at yahoo.com> wrote:> Dear mailing list members, > > I am a new R user, I would like to plot the > follewing data > > var1 <- c(1,2,1,1,2,1,2,1,2,2) > var2 <- round(rgamma(10,2,1)/0.1)*0.1 > var3 <- c(0,1,0,1,0,0,0,0,1,0) > var4 <- c(1,2,2,2,1,1,1,1,1,1) > > Var <- data.frame(var1,var2,var3,var4) > Var <- Var[sort(Var$var1),] > tt <- Var$var1+((runif(length(Var$var1))/6)-(0.5/6)) > labelname <- c("time 1", "time 2") > > plot(tt,var2,xaxt = "n") > axis(1,1:length(unique(var1)), labelname) > > Could you tell me please how can I get diffrent > colour and plotting symbols according to var3 and > var4, respectively. > > Diego! > > > >____________________________________________________________________________________> Looking for last minute shopping deals? > > [[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. >[[elided trailing spam]]