[R] How to plot graph with different scale (y axis) on same graph?

David Winsemius dwinsemius at comcast.net
Thu Apr 26 16:03:59 CEST 2012


On Apr 26, 2012, at 7:31 AM, Jim Lemon wrote:

> 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.

Another option would be to use plotting methods that encode the local  
density with color or symbols. Package:hexbin has been useful in my  
experience. Might not do as well with overplotting strategies,  
though.  I have also used 2d kernel density estimates and gotten  
useful results with overlaying the resulting contour plots.

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list