library(mapdata) eqdata<-read.table(text="",col.names=c("time", "longitude", "latitude", "depth", "mag")) ymd<-seq(as.Date("2016-04-14"),as.Date("2016-04-19"), by="1 day") for (i in 1:length(ymd)){ date<-gsub("-","",ymd[i]) url<-paste0("http://www.data.jma.go.jp/svd/eqev/data/daily_map/",date,".html") doc<-readLines(url,encoding ="UTF-8") kensaku<-paste0(substr(date,1,4)," ",gsub("\\<0"," ",substr(date,5,6))," ",gsub("\\<0"," ",substr(date,7,8))) x<-doc[grep(paste0("\\<",kensaku),doc)] x<-gsub("°", " ",x) time<-paste0(substr(x,1,4),"-",substr(x,6,7),"-",substr(x,9,10)," ",substr(x,12,16),":",substr(x,18,21)) latitude = as.numeric(paste0(substr(x,23,23),as.character(as.numeric(substr(x,24,25))+as.numeric(substr(x,28,29))/60+as.numeric(substr(x,31,31))/600))) longitude = as.numeric(paste0(substr(x,34,34),as.character(as.numeric(substr(x,35,37))+as.numeric(substr(x,40,41))/60+as.numeric(substr(x,43,43))/600))) depth<-as.numeric(substr(x,48,50)) mag<-as.numeric(substr(x,55,58)) eq<-data.frame(time,longitude,latitude,depth,mag) eqdata<-rbind(eqdata,subset(eq,mag>=-4)) } eqdata<-unique(eqdata) summary(eqdata) eqdata1<-subset(eqdata,depth<10) eqdata1$depth_rank<-" 10km 未満" eqdata1$col<-"red" eqdata2<-subset(eqdata,depth>=10 & depth<20) eqdata2$depth_rank<-" 10km以上20km未満" eqdata2$col<-"orange" eqdata3<-subset(eqdata,depth>=20 & depth<40) eqdata3$depth_rank<-" 20km以上40km未満" eqdata3$col<-"gold4" eqdata4<-subset(eqdata,depth>=40 & depth<80) eqdata4$depth_rank<-" 40km以上80km未満" eqdata4$col<-"green" eqdata5<-subset(eqdata,depth>=80 & depth<150) eqdata5$depth_rank<-" 80km以上150km未満" eqdata5$col<-"blue" eqdata6<-subset(eqdata,depth>=150) eqdata6$depth_rank<-"150km以上" eqdata6$col<-"purple" eq<-rbind(eqdata1,eqdata2,eqdata3,eqdata4,eqdata5,eqdata6) #並べ替え:マグニチュードの昇順 sortlist <- order(eq$mag) eq<- eq[sortlist,] ## #mag>=1の地震を抽出 subeq<-subset(eq,mag>=1) mag1und<-subset(eq,mag<1) par(family = "TakaoExMincho") map('japan',fill=T,col="gray90") map('japan',col="gray50",boundary =F,add=T) points(subeq$longitude,subeq$latitude,cex=(subeq$mag-0.2)/2,bg=adjustcolor(subeq$col,1),pch=21,col="black") par(xpd=T) cexsize=(c(1,3,5,7,9)-0.2)/2 legend(par("usr")[2]*1.001,par("usr")[3]*0.05+par("usr")[4]*0.95,title="Magnitude", legend = c("M=1","M=3","M=5","M=7","M=9"), col=1,pch=21,pt.cex=cexsize, cex =1,bg ="gray90", x.intersp = 2, y.intersp =1.8,bty = "n") legend(par("usr")[2],par("usr")[3]*0.6+par("usr")[4]*0.4,title="Depth", legend = c("D<10km","10km<=D<20km","20km<=D<40km","40km<=D<80km","80km<=D<150km","150km<=D"), cex=1,pch=19,col=c("red","orange","gold4","green","blue","purple"), pt.cex =1.5,bg ="gray90", x.intersp = 1, y.intersp =1.2,bty = "n") par(xpd=F) title(paste0(ymd[1],"~",ymd[length(ymd)]," 地震(Magnitude >=1)")) title("","( データ:気象庁 震源リスト )",line=2) map.axes(cex.axis=0.8,las=1)
|