2016-08-21 659 views
1

有人能解釋爲什麼右側軸標籤沒有出現?在右側添加y軸時不會顯示軸標籤

df_up<-data.frame(cutoff=c(1:10),percentage_accuracy=seq(.1,1,by=.1)) 
df_down<-data.frame(cutoff=c(2:11),percentage_accuracy=runif(10, 0, 1)) 


plot(x=df_up$cutoff,y=df_up$percentage_accuracy, main="RSI predicting trend",ylab=NA,xlab="RSI cutoff value",col="blue",type="p") 
mtext(side = 2, line = 3, "% successful upward predictions") 
par(new = T) 
plot(x=df_down$cutoff,y=df_down$percentage_accuracy,axes=F,xlab=NA,ylab=NA,col="red",type="p") 
axis(side = 4) 
mtext(side = 4, line = 3, '% successful downward predictions') #THIS DOESNT APPEAR 
legend("top",legend=c("% successful upward predictions", '% successful downward predictions'), pch=c(1,1),col=c("blue", "red")) 

enter image description here

+0

這正是我試圖做。你是怎麼得到這樣的照片的? – Rilcon42

回答

2

你需要設置你的圖形設備的右邊緣。默認頁邊距爲:

par("mar") 
# [1] 5.1 4.1 4.1 2.1 

您看到右側是2.1,而左側是4.1。如果您想在兩側都使用兩個y軸,請將兩個邊距設置爲相同。

new_par <- old_par <- par("mar") 
new_par[4] <- old_par[2] 
par(mar = new_par) 

## your code, unchanged 

par(mar = old_par) 

enter image description here