双坐标轴柱状图
setwd(“H:/分析评价 20220531/6-分析过程”) #设置工作路径
library(xlsx)#加载excel文件包
#----------------------------------------------------------------------------------------------------------
tiff(file=“1-占比.tiff”,res=600,width=6000,height=4000,compression=“lzw”) #设置输出图片名称
par(mar=c(6, 6, 6, 6) + 0.1)
a= read.xlsx(“2-计算数据.xlsx”,sheetIndex = 1) #读取excel文件
Plot first set of data and draw its axis
b <- seq(1,21,1)
plot(b,a$小计.01.,pch=16, axes=FALSE, ylim=c(0,700), xlab=“”, ylab=“”,
type=“b”,col=“black”,font.axis = 1,lwd=2)
axis(2, ylim=c(0,700),col=“black”,las=2,family = “serif”,font.axis = 2,lwd=2,cex.axis=1.5) ## las=1 makes horizontal labels
mtext(“面积(万亩)”,side=2,line=3,family = “serif”,font = 2,cex = 2)
box(lwd=2)
Allow a second plot on the same graph
par(new=TRUE)
Plot the second plot and put axis scale on right
plot(b, a$占比.01., pch=15, xlab=“”, ylab=“”, ylim=c(0,30),
axes=FALSE, type=“h”, col=“#63C600FF”,family = “serif”,font.axis = 1,lwd=15)
a little farther out (line=4) to make room for labels
axis(4, ylim=c(0,30), col=“#63C600FF”,col.axis=“#63C600FF”,las=2,family = “serif”,lwd=2,cex.axis=1.5)
mtext(“占比(%)”,side=4,col=“#63C600FF”,line=3,family = “serif”,font = 2,cex = 2)
Draw the time axis
axis(1,pretty(range(b),21),family = “serif”,font.axis = 2,lwd=2,cex.axis=1.5)
Add Legend
legend(“topright”,legend=c(“面积”,“占比”), text.col=c(“black”,“#63C600FF”),pch=c(16,15),col=c(“black”,“#63C600FF”),text.font =10,bty=“n”)
dev.off()