Manish Gupta
2012-Apr-26 10:02 UTC
[R] How to plot graph with different scale (y axis) on same graph?
Hi, I have my data in below format. position var1 var2 2 .1 10 3 .29 89 12 .56 100 425 .34 1234 6546 .12 21 .... ..... ..... .... ..... ...... .... ..... ...... I need to plot a grpah for above with position as x - axis and two variables with as line on the same plot. I have 5 million records. How can i implement it efficiently. Regards -- View this message in context: http://r.789695.n4.nabble.com/How-to-plot-graph-with-different-scale-y-axis-on-same-graph-tp4589364p4589364.html Sent from the R help mailing list archive at Nabble.com.
ghostwheel
2012-Apr-26 10:35 UTC
[R] How to plot graph with different scale (y axis) on same graph?
You ask two questions. First, how to put points with a different y-axis on the plot. One possibility s like this:> plot(1:10) > plot.window(xlim=c(1,10),ylim=c(1,100)) > points( seq(1,10,length=100), 100:1, col=2 ) > axis(4,col.axis=2,col=2)The command plot.window is the one that changes the range for ylim. The second question is about plotting 5 million data points. Since it is very hard to really take in 5 million data points, I'd subsample the plot, so do x=1:5e6 y=x^2 i=sample( seq( along=y ), 1e4 ) plot( x,[i], y[i] , pch=".") If you do plot 5 million points, I'd plot them on a raster device, like png. In if you plot them in pdf or postscript, printing/viewing the result will take a long time. So do something like png("bigplot.png") plot(x,y,pch=".") -- View this message in context: http://r.789695.n4.nabble.com/How-to-plot-graph-with-different-scale-y-axis-on-same-graph-tp4589364p4589416.html Sent from the R help mailing list archive at Nabble.com.
Jim Lemon
2012-Apr-26 11:31 UTC
[R] How to plot graph with different scale (y axis) on same graph?
On 04/26/2012 08:02 PM, Manish Gupta wrote:> Hi, > > I have my data in below format. > > position var1 var2 > 2 .1 10 > 3 .29 89 > 12 .56 100 > 425 .34 1234 > 6546 .12 21 > .... ..... ..... > .... ..... ...... > .... ..... ...... > > I need to plot a grpah for above with position as x - axis and two variables > with as line on the same plot. I have 5 million records. How can i > implement it efficiently. >Hi Manish, You can plot this with twoord.plot (plotrix): position<-c(2,3,12,425,6546) var1<-c(.1,.29,.56,.34,.12) var2<-c(10,89,100,1234,21) library(plotrix) twoord.plot(lx=position,ly=var1,rx=position,ry=var2) but with 5 million records you will just have a jagged block of color. I think ghostwheel's suggestion of reducing the number of points is very sensible. Jim