在右侧添加y轴时,轴标签不显示

时间:2016-08-21 18:16:26

标签: r plot

有人可以解释为什么没有出现右手轴标签吗?

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

1 个答案:

答案 0 :(得分: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