<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/rclimate-script-to-assess-local-hot-day-trends/"></div></div><div><a data-url="https://www.r-bloggers.com/rclimate-script-to-assess-local-hot-day-trends/" data-counturl="https://www.r-bloggers.com/rclimate-script-to-assess-local-hot-day-trends/" data-count="horizontal" data-text="RClimate Script to Assess Local Hot Day Trends" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rclimate.wordpress.com/2016/08/29/rclimate-script-to-assess-local-hot-day-trends/"> RClimate</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>There is ample evidence of global climate change, these are just a few examples  (<span><strong><a target="_blank" href="http://www.ucsusa.org/our-work/global-warming/science-and-impacts/global-warming-science#.V8TKYygrLDc">here</a></strong></span>, <span><strong><a target="_blank" href="http://dels.nas.edu/resources/static-assets/exec-office-other/climate-change-full.pdf">here</a></strong></span>, <span><strong><a target="_blank" href="http://www.ucsusa.org/our-work/global-warming/science-and-impacts/global-warming-science#.V8TKYygrLDc">here</a></strong></span>).</p>
<p>While global indicators are important to focus attention on the problem and solutions, local data is important to help us understand the situation in our own areas.  There are a number of R packages that let users download and analyze weather data to investigate the climate change situation in local geographic areas.</p>
<p>I find the weatherData package an excellent tool for local climate change investigations. AS an example, I downloaded daily weather data for my local airport  for the period 1950 – 2015, ran a simple r-script to count and save the number  of 90+ days each summer period to a csv file. This hot day trend chart is an  example  of what R users can do to visualize the changing climate.<a target="_blank" href="https://i2.wp.com/rclimate.files.wordpress.com/2016/08/hot_day_trend_-kphl.png?ssl=1"><img alt="hot_day_trend_ KPHL" class="wp-image-195" src="https://i2.wp.com/rclimate.files.wordpress.com/2016/08/hot_day_trend_-kphl.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<p>This chart shows that the number of 90+ days in Philadelphia has increased in the past 66 years. Prior to 1983 (midpoint of period), only 5 out of 30 years have 30 or more days of 90+ max temperatures. Since 1984,  13 of 36 years had 30 or more days of 90+ max temperatures.  2016 has had 38 days through August 28, making 16 of 37 years with 30 or more 90+ days.</p>
<p>My R script is reproduced below. My  R base graphics script could be easily reproduced in ggplot2.</p>
<pre>
  library(weatherData)
  library(stats)
  airport &lt;- &quot;KPHL&quot;
## user can specify moving average period 
  ma_period &lt;- 10
  ma_legend &lt;- paste(ma_period,&quot; year moving avg&quot;)  
  
  setwd(&quot;F:\\enter woring directory here &quot;)
 
## Read data from prev downloaded weather data file
  input_file &lt;-  &quot;F:\\enter input file name.csv&quot;
  df &lt;- read.csv(input_file, as.is=T)
  start_yr &lt;- df[1,1]
  end_yr &lt;- df[nrow(df),1]
  num_yrs &lt;- end_yr -start_yr +1
  my_date &lt;- format(Sys.Date(),&quot;%m/%d/%Y&quot;)

## Use plot function to enable saving png as well as console display
 plot_func_1 &lt;- function() {
   par(las=1); par(mar=c(1,4,5,1)); par(oma = c(3,2,2,1)); par(ps=11)
   title_1 &lt;- paste(&quot;KPHL\nNumber days in year with Max temperaure >= &quot;,90,
            &quot;\n in hot weather months of May 1 - August 31\n&quot;,  start_yr, &quot; through &quot;, end_yr)
  plot(df$year, df$hot_day_count, type=&quot;n&quot;, lwd=3,
     main=title_1,  cex.main=0.8,   xlab=&quot;&quot;, ylab = &quot;Number of days&quot;,
     ylim &lt;- c(0,60),xlim=c(start_yr, end_yr) ) 
  grid(col = &quot;lightgrey&quot;, lty=1) 
  points(df$year, df$hot_day_count, type=&quot;h&quot;, col=&quot;red&quot;, lwd=2) 
 
  legend(&quot;topleft&quot;, c(ma_legend, &quot;No. days max temp >= 90&quot;, &quot;Trend Line&quot;), col = c(&quot;blue&quot;, &quot;red&quot;,&quot;black&quot;),
         text.col = &quot;black&quot;, lty = c(1),pt.cex=c(0),  x.intersp = 0.25, y.intersp = 0.7,
         merge = T, bg = &quot;transparent&quot;, bty=&quot;n&quot;, box.col = &quot;black&quot;, cex = 0.7,seg.len=1, lwd=3)
  
## calculate and add 10 year moving average to plot
  ma &lt;- stats::filter(df$hot_day_count, rep(1/ma_period,ma_period),sides=1 )
  my_seq &lt;- seq(start_yr, end_yr)
  ma_df &lt;- data.frame(my_seq, ma)
  names(ma) &lt;- c(&quot;yr&quot;,&quot;ma&quot;)
  points(ma_df$my_seq, ma_df$ma, type=&quot;l&quot;, col=&quot;blue&quot;,lw=3)  
  abline(lm(hot_day_count ~ year, data = df),col=&quot;black&quot;)
  mtext(&quot;Kelly O'Day - http://RClimate.wordpress.com&quot;, side = 1, line = 1, cex=0.7, outer = T, adj = 0)
  mtext(my_date, side = 1, line =1, cex = 0.7, outer = T, adj = 1)
         }  
  out_file &lt;-  paste(&quot;hot_day_trend_&quot;,airport,&quot;.png&quot;)  # location for png olot file
  png(file=out_file,width=1290,height=1000, res=200)  
  plot_func_1()  # send plot to png device
  dev.off()  # turn off png device
  plot_func_1()  # plot to console</pre>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rclimate.wordpress.com/192/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/rclimate.wordpress.com/192/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/rclimate-script-to-assess-local-hot-day-trends/"></div></div><div><a data-url="https://www.r-bloggers.com/rclimate-script-to-assess-local-hot-day-trends/" data-counturl="https://www.r-bloggers.com/rclimate-script-to-assess-local-hot-day-trends/" data-count="vertical" data-text="RClimate Script to Assess Local Hot Day Trends" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rclimate.wordpress.com/2016/08/29/rclimate-script-to-assess-local-hot-day-trends/"> RClimate</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/VAuH1WMsoXc"></a></div>