我尝试制作如下图。
但是我的2个y轴并没有处于不同的水平。另外,我不能将左Y轴“WD”设置为“红色”
有没有人可以帮我弄清楚这两个问题?
非常感谢!
DLPM10$hours <- as.integer(gsub('.* |:.*', '', DLPM10$date))
dt <- group_by(DLPM10, hours) %>%
summarise(WD = mean(WD_DOUGLAS, na.rm = TRUE), WS = mean(WS_DOUGLAS, na.rm = TRUE))
par(mar=c(5,4,4,5)+.1)
barplot(height = dt$WD, axes=FALSE, border =NA,space = 0.4,ylim=c(0,370),
col="red",xlab = 'Hour', ylab = 'WD', main = "Dougals Red Cross")
axis(2, ylim=c(0,370),col="red",col.axis="red",col.lab="red",las=1)
par(new = TRUE)
plot(dt$hours, dt$WS,axes = FALSE, bty = 'n',pch= 19,xlim = c(-.35, 23.35),
ylim=c(0,5), col="blue", xlab = '', ylab = '')
axis(4, 0:5, col="blue", col.axis="blue",las=1)
mtext('WS', dt$WS,col="blue", side = 4, line = 2)
axis(1, 0:23, pos = -0.2)
legend("topleft",legend=c("WS","WD"),bty = "n",
bg = par("bg"),
text.col=c("blue","red"),pch=c(19,15),
col=c("blue","red"),horiz= T,text.width= 0.01)
答案 0 :(得分:0)
喜欢这个?
par(mar=c(5,4,4,4))
plot(1, axes=FALSE, ylab='', ylim=c(0,370), xlim = c(-.35, 23.35), col=0)
mtext("WD", side=2, line=3, col="red", cex=1)
mtext("WS", side=4, line=3, col="blue", cex=1)
axis(1, 0:23, pos = -0.2)
axis(2, ylim=c(0,370),col="red",col.axis="red",col.lab="red")
axis(4, at=c(0:5)*370/6,labels=0:5, col="blue", col.axis="blue",las=1)