2017-09-14 148 views
0

我有一些气象数据,我正在绘制一个显示月平均值的时间序列。我在同一块剧情画布上将降雨量作为一个条线图和温度作为线条图。我需要生成一个带有不同符号的图例,例如降雨的彩色框,以及两个用于温度的彩色线。酒吧和线图的图例组合

这里的数据

> month max_temp min_temp  rain  humid 
    >  Jan 24.65032258 12.54193548 1.425806452 75.44064516 
    >  Feb 25.65248227 13.39219858 1.876595745 79.06666667 
    >  Mar 24.26129032 12.41354839 2.318709677 83.55806452 
    >  Apr 21.038  10.62933333 5.013333333 90.026 
    >  May 17.29548387 7.16516129 4.080645161 91.83225806 
    >  Jun 14.98733333 5.529333333 4.4   91.2 
    >  Jul 13.98516129 4.06516129 3.987096774 90.60322581 
    >  Aug 15.18258065 5.316129032 3.350322581 89.26129032 
    >  Sep 16.434  7.668  4.229333333 84.03666667 
    >  Oct 18.13225806 8.481290323 2.277419355 81.26129032 
    >  Nov 20.07666667 9.558666667 2.562  75.99266667 
    >  Dec 22.51032258 12.13225806 2.296774194 76.28193548 

这是我的代码来生成情节

weather<-weather 
month_number<-seq(1,12,1) 
months<-months[1:12] 
new<-data.frame(rain=c(weather$rain),order=c(months)) 
graph<-barplot(height=new$rain, names.arg=new$order,col="light blue", 
    cex.axis=0.2,border=NA,xaxt='n',yaxt="n",xlab="",ylab="",ylim=c(0,10)) 
axis(side=1, pos=0,tck=-0.05,at=graph, labels=months[1:12],cex.axis=0.7,las=2,font.axis=2) 
axis(4,las="1",cex.axis=0.7,font.axis=2) 
mtext("Accumulated rainfall (mm)",side=4,line=2,cex=0.7) 
par(new=TRUE) 
weather$x<-month_number 
plot(weather$x,weather$max_temp,type="l",las=1,col="red",lwd=1.5,xaxt="n", 
    ylim=c(0,30),xlab=NA,ylab = expression(paste("Temperature ",degree,"C")), 
    ,cex.lab=0.8,cex.axis=0.7,font.axis=2) 
lines(weather$x,weather$min_temp,col="blue",lwd=1.5) 
legend("bottom",inset=c(0,1.05),legend=c("Rainfall", "Max temp", "Min temp"),xpd=TRUE, 
     ,horiz=TRUE,pch=c(15),col=c("light blue","red","blue"), 
     lty=c(0,1,1),lwd=2,title=NA,cex=0.6,bty='n') 

和剧情本身。在图例中,我想增加降雨情节字符的大小,并完全忽略这两个温度的行中显示的情节字符。字体大小需要保持不变。我试过pch=26,我有seen plots a null character但我收到一条错误消息。也looked here但它并没有解决我的问题。

Weather data

回答

0

这里是你将如何省略的情节中的人物线(例如使用pch=c(19,NA,NA)):

legend("bottom",inset=c(0,1.05),legend=c("Rainfall", "Max temp", "Min temp"),xpd=TRUE, 
     ,horiz=TRUE,pch=c(19,NA,NA),col=c("light blue","red","blue"), 
     lty=c(0,1,1),lwd=2,title=NA,cex=0.6,bty='n') 

要在行获得剧情人物不和,使降雨情节人物大,我会用fill

legend("bottom",inset=c(0,1.05),legend=c("Rainfall", "Max temp", "Min temp"),xpd=TRUE, 
     ,horiz=TRUE,col=c("light blue","red","blue"), fill=c("light blue", NA,NA), border = c("light blue", NA,NA), 
     lty=c(0,1,1),lwd=2,title=NA,cex=0.6,bty='n')