Analysis and forecast of the weather in Suzhou by R language

Source: Internet
Author: User

Coordinates Suzhou, come here just a year, and to April, the rainy season (? The most can feel the misty beauty of Jiangnan, just strange! In fact, the mood is, "qingming season rain, holiday home to Rains", has been unable to spit groove this spring and summer combat winter breakout Strange weather changes, just have time, so want to use the high technical language to read the weather characteristics of Suzhou.

Historical weather Data Source: http://tianqi.2345.com/wea_history/54511.htm, which is the historical data of Beijing, sampling the cities of Beijing, Shanghai, Suzhou, Changsha, Guangzhou, Collected from 2011-1-1 to 2015-4-2 this 4 years three months a total of 1542 (354+366+365+365+92) days of the weather data, 2011-1-17 to 2011-1-25 this 10 days of data missing, looked at a number of sites found this situation, There was no data to be filled. In addition, Shanghai, Suzhou, Guangzhou, three cities in 2012-1-15 this day, Changsha 2015-2-10 this day, five cities 2014-3-8 this day of data missing, here according to the temperature of two days before and after the average, the weather is set to Yin, wind after the wind are based on the day before and after. The following two figures are missing from the historical weather data found on two different websites.


After cleaning up the data, save the CSV format, enter the data into R, and view the basic structure of the data as follows:

Beijing <-read.csv ("Beijing.csv", Header=t,stringsasfactors=false) Changsha <-read.csv ("Changsha.csv", header =t,stringsasfactors=false) Guangzhou <-read.csv ("Guangzhou.csv", Header=t,stringsasfactors=false) Shanghai <- Read.csv ("Shanghai.csv", Header=t,stringsasfactors=false) Suzhou <-read.csv ("Suzhou.csv", Header=t, Stringsasfactors=false) Head (suzhou,n=5)


Each column is: Date (date), highesttemp (maximum temperature), lowest (lowest temperature), weather (weather), wind (direction), WindForce (wind).

Weather articles

Statistics of the basic weather type: Snow, rain, clear, overcast, priority order is also the case, that is, if it is snow and rain weather, recorded as a snowy, sunny to cloudy, in addition cloudy and Yin are recorded as Yin, here is a link to explain the weather and cloudy differences, mainly the difference in cloudiness size, http:// www.guokr.com/question/252793/, here I unify it as Yin, as well as fog, haze, dust weather all remember to do Yin.

Weatherstat <-function (x) {count <-numeric (0) Count[1:5] <-0for (i in 1:length (X[[4])) {if (Length (grep ("Snow", X[[4]][i]))                    >0) {count[1] <-count[1]+1}else if (Length (Grep ("Rain", X[[4]][i]) >0) { COUNT[2] <-count[2]+1}else if (grep ("clear", X[[4]][i])) >0) {count[3] <-Coun T[3]+1}else if (Length (grep ("Yin", x[[4]][i])) >0) | | (Length (grep ("Cloudy", X[[4]][i])) >0) | | (Length (grep ("Fog", X[[4]][i])) >0) | | (Length (grep ("Haze", X[[4]][i])) >0) | | (Length (grep ("Speck", X[[4]][i]))) (>0)) {count[4] <-count[4]+1}else{count[5] <-C Ount[5]+1 print (X[[4]][i])}}count} statall<-list (Beijing=numeric (0), Suzhou =numeric (0), shanghai=numeric (0), changsha=numeric (0), guangzhou=numeric (0)) statall$suzhou<-weatherStat (Suzhou ) statall$beijing<-Weatherstat (Beijing) Statall$shanghai<-Weatherstat (Shanghai) statall$changsha<-Weatherstat (Changsha) statall$guangzhou<-WeatherStat ( Guangzhou) statall<-as.data.frame (statall) statall<-statall[-5,] #第五行, is the statistics in addition to these four kinds of weather and whether there are other conditions, five cities are 0, so delete this line, Front fog, haze, dust are found in this category and then finishing to the yin below the Rownames (Statall) <-C ("Snow", "Rain", "clear", "Yin") colnames (Statall) <-C ("Beijing", "Suzhou", "Shanghai", "Changsha" , "Guangzhou") statallstatall<-As.matrix (Statall) Barplot (Statall,legend=true,col=c ("snow3", "Lavender", "khaki1", " LemonChiffon "))


This simple statistic can be seen basically farther south, the more sunny, rainy day is compared to the south more than the north, the snow is more north than the south, but here the north only took a city in Beijing. Here I found to Suzhou I seem to have a little misunderstanding, compared to Changsha, where the rainy day is still relatively small, why I always have the kind of a holiday on the feeling of rain?

Just look at the weather conditions in Suzhou and see a statistic of the following years:

#2011年1:354,2012 355:720,2013 year 721:1085,2014 1086:1450,2015 years 1451:1542statsuzhou<-list (one=numeric (0), two= Numeric (0), three=numeric (0), four=numeric (0), five=numeric (0)) statsuzhou$one<-weatherstat (suzhou[1:354,]) statsuzhou$two<-Weatherstat (suzhou[355:720,]) statsuzhou$three<-Weatherstat (suzhou[721:1085,]) statSuzhou$ four<-Weatherstat (suzhou[1086:1450,]) statsuzhou$five<-Weatherstat (suzhou[1451:1542,]) statSuzhou<- As.data.frame (Statsuzhou) statsuzhou<-statsuzhou[-5,] #第五行, is the statistics in addition to these four kinds of weather and whether there are other conditions, five cities are 0, so delete this line rownames ( Statsuzhou) <-C ("Snow", "Rain", "clear", "Yin") colnames (Statsuzhou) <-c ("2011", "2012", "2013", "2014", "2015") statsuzhoustatsuzhou<-As.matrix (Statsuzhou) Barplot (Statsuzhou,legend=true,col=c ("snow3", "Lavender", "khaki1" , "LemonChiffon"))


Suzhou weather, sunny days In addition to 2013 years are under 30%, 2013 weather is very good? Can look at the temperature in 2013 years there is nothing unusual.



So what's the difference between the rainy months? Can you see the time of the concentrated rainfall? Next, do a weather statistic based on the month.

? Check out the normal rainy season should be from June to July, the rainy season in front of me is not appropriate, here will not change.

statmonthly<-data.frame () statmonthly[1:5,1]count<-1for (i in2011:2015) {if (i! =) {for (J in 1:12) { Temp <-nrow (Suzhou[grep (Paste (I, "-", J, "-", sep= ""), Suzhou$date),]) Statmonthly[1:5, ((i-2011) *12+j)]                    <-Weatherstat (suzhou[count: (count+temp-1),]) print (Weatherstat (suzhou[count: (count+temp-1),]))  Print (C (((i-2011) *12+j)) Count <-Count + temp}}else{for (J in 1:3) {temp <-nrow (suzhou[grep (Paste (I, "-", J, "-", sep= ""), Suzhou$date),]) Statmon Thly[1:5, ((i-2011) *12+j)]<-Weatherstat (suzhou[count: (count+temp-1),]) print (Weatherstat (Suzhou[coun T: (Count+temp-1),]) print (C (((i-2011) *12+j)) Count <-Count + temp}} } statmonthly<-statmonthly[-5,]rownames (statmonthly) <-C ("Snow", "Rain", "clear", "Yin") colnames (statmonthly) <-c (paste (Rep (2011,12), 1:12,sep= "-"), Paste (Rep (2012,12), 1:12,sep= "-"), Paste (Rep (2013,12), 1:12,sep= "-"), Paste (Rep (2014,12), 1:12,sep= "-"), Paste (Rep (2015,3), 1:3,sep= "-")) statmonthly<-As.matrix (statmonthly) Barplot (Statmonthly,legend=true,col=c (" Snow3 "," Lavender "," khaki1 "," LemonChiffon ")) Barplot (Statmonthly,col=c (" snow3 "," Lavender "," khaki1 "," LemonChiffon "), cex.names=.6) lines (statmonthly[2,],type=" L ", col=" Red ") statmonthly



The above is a monthly statistic of the weather results map, you can see that the rain and snow in 4-8 months will be relatively concentrated, the red line marked by the portion of the corresponding annual 4-August. And in 2013, the rain and snow days compared to less. But the horizontal axis is too long to look very laborious.

The following does not consider 2015 years of data, see 2011-2015 years, monthly weather statistics.

statmonthly2<-data.frame () temp<-1:51for (i in1:12) {if (i==12) {for           (j in 1:4) {                    statmonthly2[j,12]<- SUM (statmonthly[j,temp%%12==0&temp<49])                     }    }else{for    (Jin 1:4) {               statmonthly2[j,i]<-sum (statmonthly[j,temp%%12==i&temp<49])}}}    Rownames (StatMonthly2) <-C ("Snow", "Rain", "clear", "Yin") colnames (statMonthly2) <-1:12statmonthly2<-As.matrix ( StatMonthly2) Barplot (Statmonthly2,col=c ("snow3", "Lavender", "khaki1", "LemonChiffon"), cex.names=.8)

Here it is clear that the rainfall is more than the month from June-August, it is the rainy season, but the rest of the month the rainfall is not very large. The more obvious is Beijing, such as:


Here is a statistical analysis of the weather, you can see that Suzhou is a very typical Jiangnan city, rain and snow more than the weather, and all year round, June-August slightly more. The analysis of these four years, 2013 more special, rainy days less sunny time is more. And I'm more concerned about the April, from the statistical results of the look, cloudy rain time looks very average. When it is windy and rainy, please remember that there is less than 30% chance of a sunny day, so rainy days, normal!

Temperature article to be continued.

Have any questions suggest welcome correct, reprint Please indicate source, thank you!

Analysis and forecast of the weather in Suzhou by R language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.