[R] All curves with same y-axis scale

Jim Lemon jim at bitwrit.com.au
Mon Nov 4 12:13:11 CET 2013


On 11/04/2013 08:54 PM, mohan.radhakrishnan at polarisft.com wrote:
> Hi,
>
> When I plot 3 curves with the same x-axis and same y-axis, the first two
> curves honor the y-axis but the last one doesn't. When I remove yaxt="n"
> for the last curve a new scale appears on the y-axis along with the scales
> that the first two curves use. I want all curves to use the same y-axis
> scale.
>
> What is missing ?
>
>         Init             Used        Committed    Max        Time
> 1   2359296 13913536  13959168 50331648   200
> 2   2359296 13915200  13959168 50331648   400
> 3   2359296 13947712  13991936 50331648   600
> 4   2359296 13956224  13991936 50331648   800
> 5   2359296 13968832  14024704 50331648  1000
> 6   2359296 13978048  14024704 50331648  1200
> 7   2359296 14012416  14090240 50331648  1400
> 8   2359296 14450304  14548992 50331648  1600
> 9   2359296 14521024  14548992 50331648  1800
> 10  2359296 14536320  14548992 50331648  2000
> 11  2359296 14553344  14581760 50331648  2200
>
> plot(data$Time,as.numeric(data$Used),col="green",pch=16,type="b",
> ylab="MegaBytes", xlab="",las=2,lwd=2,xaxt="n", cex.lab=1.2,cex.axis=1)
> axis(1,at = seq(min(data$Time), max(data$Time), by=1000),las =
> 2,cex.axis=1)
> title("Time vs Used Code cache,Committed and Maximum Code
> cache",cex.main=1.5,xlab="Time(Seconds)")
>
> par(new=T)
> plot(data$Time,as.numeric(data$Committed),col="orangered",pch=16,type="b",
> ylab="MegaBytes", xlab="",las=2,lwd=2,xaxt="n",
> cex.lab=1.2,cex.axis=1,yaxt="n")
>
> par(new=T)
> plot(data$Time,as.numeric(data$Max),col="palevioletred3",pch=16,type="b",
> ylab="MegaBytes", xlab="",las=2,lwd=2,xaxt="n",
> cex.lab=1.2,cex.axis=1,yaxt="n")
>
Hi Mohan,
This is because the ranges of "Used" and "Committed" are so close that 
you probably didn't notice the difference. "Max" is just a straight line 
way off the two original plots. If you want to show these three widely 
varying values on the same plot, use the lines or points function for 
the second two sets of values and set your ylim in the first plot to 
contain all the values to be plotted.

You might also look at the gap.plot function in plotrix if you want to 
avoid two lines at the bottom of the plot and one line right at the top:

gap.plot(data$Time,data$Used,gap=c(15000000,49000000),
  ylim=c(13500000,50500000),type="b",pch="U")
gap.plot(data$Time,data$Committed,gap=c(15000000,49000000),
  type="b",pch="C",add=TRUE)
gap.plot(data$Time,data$Max,gap=c(15000000,49000000),
  type="b",pch="M",add=TRUE)

Jim



More information about the R-help mailing list