2012-02-06 84 views
2

如何使用plot()將XY圖中的第二條線繪製到不同的比例尺,如此示例(紫色線)?R中的XY圖上的多軸/比例尺

enter image description here

第一(紅)線我的R代碼裏面是一樣的東西:

p <- sqlQuery(ch,"SELECT wl,param1 FROM qryPlot ORDER BY wl") 
plot(p$wl,p$param1,axes=T,xlim=c(400,800),ylim=c(0,100),type="l",col="red") 
+0

我覺得這個問題也已經解決了。讓我試着找到另一個Q/As ... – 2012-02-06 16:09:56

+3

http://stackoverflow.com/questions/5479822/plotting-4-curves-in-a-single-plot-with-3-y-axes-in- r http://stackoverflow.com/questions/6142944/how-can-i-plot-with-2-different-y-axes-in-r – 2012-02-06 16:11:25

+0

它也在R-FAQ中。 – 2012-02-06 16:34:35

回答

8

這裏的總體思路是:

plot(1:10) 
par(new=T) 
plot(1:10, rep(50, 10), type='l', axes=F, xlab=NA, ylab=NA) 
axis(4) 

enter image description here

0

我微微@johncolby將答案擴展爲:

x<-1:20 
y1<-sqrt(x) 
y2<-sqrt(x)*x 
plot(x,y1,ylim=c(0,25),col="blue") 
par(new=TRUE) 
plot(x,y2,ylim=c(0,100),col="red",axes=FALSE) 
axis(4) 

axes=FALSE在第二曲線()命令=,以防止標籤打印在左側第二軸)

通過該結果:

enter image description here

解決小問題:標籤兩個y軸都印在左側。