[R] Plotting with 2 y axes

jim holtman jholtman at gmail.com
Sat Oct 13 04:42:15 CEST 2007


basically something along these lines:

plot(Time, Resistance, bty='c')
par(new=TRUE)
plot(Time, Temperature, axes=FALSE, ylab='', xlab='')
axis(4)

On 10/12/07, Keith Cox <kcox at sj-alaska.edu> wrote:
> My data is the following:
>
>
>
>
> Time
>
> Resistance
>
> Temperature
>
>
> 5
>
> 2000
>
> 4
>
>
> 10
>
> 2200
>
> 8
>
>
> 15
>
> 2500
>
> 14
>
>
> 20
>
> 2900
>
> 20
>
>
> 25
>
> 3000
>
> 29
>
>
> 30
>
> 3100
>
> 38
>
>
> 35
>
> 3500
>
> 46
>
>
> 40
>
> 3800
>
> 47
>
>
> 45
>
> 3900
>
> 50
>
>
> 50
>
> 4000
>
> 51
>
>
>
> I would like to create a scatter plot with Time on the x axis, Resistance on
> the y axis and Temperature on a second y axis.
>
>
>
> I have tried
>
> Plot(Time,Resistance,ylim=range(0,4500)
>
> Points(Time,Temperature)
>
> Axis(side=4)
>
>
>
> But the temperature ends up as a straight line along the bottom.  I also
> tried
>
> plot(time, resistance, ylim=c(0,4500), col="black", type="b") points(time,
> 4500/60 * temperature, col="green", type="b") axis(side=4,
> at=4500/60*seq(0,60, by=10), labels=seq(0,60,by=10))
>
>
>
> but that just scales temperature appropriately to match the Resistance and
> does not plot off of a second y axis.  I have many plots to create and need
> resistance plotted on one y axis and Temperature plotted on the second.
>
>
>
> Thanks in advance, keith
>
>
>
>
>
> Marlin Keith Cox Ph.D.
>
> At-Sea Processor Professorship of Fisheries Biology
> Science Chair
>
> Sheldon Jackson College
>
> Sitka, Alaska 99835
>
> 907.747.5296
>
> http://www.sheldonjackson.edu
>
>
>
>
>        [[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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list