Hello I was wondering how I can achieve matlab style plotting in R, in the sense that matlab allows you to plot multiple sets of variables within the same x-y axes. plot in R does not seem to cater for this. I tried 'overplot' from the gplots package but this assumes different y axes for the variables. any suggestions would be very appreciated Maria [[alternative HTML version deleted]]
In traditional R graphics, you can take a look at "matplot".
You might also want to look at the lattice package.
Hope this helps,
Matt Wiener
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Maria
Vatapitakapha
Sent: Tuesday, February 13, 2007 12:20 PM
To: r-help at stat.math.ethz.ch
Subject: [R] matlab style plotting in R [Broadcast]
Hello
I was wondering how I can achieve matlab style plotting in R,
in the sense that matlab allows you to plot multiple sets of variables
within the same
x-y axes. plot in R does not seem to cater for this. I tried 'overplot'
from
the gplots package but this assumes different y axes for the variables.
any suggestions would be very appreciated
Maria
[[alternative HTML version deleted]]
______________________________________________
R-help at stat.math.ethz.ch 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.
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments,...{{dropped}}
try ?lines ?points On 2/13/07, Maria Vatapitakapha <xrysoflis at gmail.com> wrote:> Hello > > I was wondering how I can achieve matlab style plotting in R, > in the sense that matlab allows you to plot multiple sets of variables > within the same > x-y axes. plot in R does not seem to cater for this. I tried 'overplot' from > the gplots package but this assumes different y axes for the variables. > > any suggestions would be very appreciated > > Maria > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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 Maria,
I'm interested in the responses you get. The way I do this is to use
par(new=TRUE), which tells R not to clean the frame before plotting
the next plot. So, eg
###Overlaid plot
op <- par(mar = c(5, 4, 4, 5) + 0.1, las = 2)
plot(x=1:5,y=rnorm(5)+1:5,type='b',xlab="xlab",ylab="ylab",main="Title")
par(new=TRUE)
plot(x=1:5,y=rnorm(5),axes=FALSE,ylab="",xlab="",type='b',col="red")
axis(4,at=c(-2,-1,0,1,2),labels=c(6,7,8,9,10))
par(las=0)
mtext("Other Y",side=4,line=3)
The trick is this: if your 2nd set of Y variables are on a different
scale than your 1st set of Y-variables, you'll need to transform the
second set so that they'll be on the same scale - otherwise they won't
show up on the old plot. You'll also, of course, need to
back-transform your labels for the 2nd set of Y variables so that they
read appropriately.
A terrific site for R graphics, with lots of worked examples
(including ones similar to the one I just did), is here:
http://zoonek2.free.fr/UNIX/48_R/all.html
On 2/13/07, Maria Vatapitakapha <xrysoflis at gmail.com>
wrote:> Hello
>
> I was wondering how I can achieve matlab style plotting in R,
> in the sense that matlab allows you to plot multiple sets of variables
> within the same
> x-y axes. plot in R does not seem to cater for this. I tried
'overplot' from
> the gplots package but this assumes different y axes for the variables.
>
> any suggestions would be very appreciated
>
> Maria
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Matthew C Keller
Postdoctoral Fellow
Virginia Institute for Psychiatric and Behavioral Genetics
There are many ways if I understood what you indend to do:
example data:
toplot<-data.frame(x=c(1:5,1:5),y=rnorm(10),sbs=c(rep("a",5),rep("b",5)))
1st with plot itself:
plot(y~x,data=toplot,type="n")
lines(y~x,data=subset(toplot,sbs=="a"),type="b",pch=4,col="blue")
lines(y~x,data=subset(toplot,sbs=="b"),type="b",pch=2,col="red")
2nd with xyplot out of the lattice package:
library(lattice)
xyplot(y~x,groups=sbs,data=toplot,pch=c(2,4),main="Title")
to see some variants. My advice is to look at a good documentation at
the homepage (contributed documentation) or book ...
Maria Vatapitakapha wrote:> Hello
>
> I was wondering how I can achieve matlab style plotting in R,
> in the sense that matlab allows you to plot multiple sets of variables
> within the same
> x-y axes. plot in R does not seem to cater for this. I tried
'overplot' from
> the gplots package but this assumes different y axes for the variables.
>
> any suggestions would be very appreciated
>
> Maria
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
>