{"id":129,"date":"2011-02-09T11:39:26","date_gmt":"2011-02-09T15:39:26","guid":{"rendered":"http:\/\/web.colby.edu\/mgimond\/?p=129"},"modified":"2011-10-26T12:26:24","modified_gmt":"2011-10-26T16:26:24","slug":"summarizing-meteorological-data","status":"publish","type":"post","link":"https:\/\/web.colby.edu\/mgimond\/2011\/02\/09\/summarizing-meteorological-data\/","title":{"rendered":"R: Summarizing meteorological data"},"content":{"rendered":"<hr \/>\n<p><strong> Dowload data for this exercise here:<a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/02\/Waterville_2010.zip\">Waterville meteorological data for 2010<\/a><\/strong><\/p>\n<hr \/>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n\r\n# Load ggplot2 library\r\nlibrary(ggplot2)\r\n\r\n# Load data and convert date field to a date (POSIX) object.\r\n# The date\/time is in standard time.\r\nmet.raw = read.csv ( &quot;waterville_2010.csv&quot;,\r\n                     na.strings=c(&quot;NaN&quot;,&quot;M&quot;),header=T)\r\n# extract date\/time column. No DST.\r\nmet.date = strptime(met.raw$Date,\r\n                     format = &quot;%m\/%d\/%Y %H:%M&quot;, tz=&quot;EST&quot;)  \r\nmet.1 = met.raw[, -1] # Remove original data\/time\r\nmet = data.frame(date = met.date,met.1) # Append date\/time formatted data \r\n# column to met.1 (overwrite met object)\r\n#\r\n# Plot monthly statistics\r\nmonth.year = function (x) {as.POSIXlt(x)$mon + 1} # get months lis\r\nmonth = month.year(met$date)\r\nMonth = factor(month, levels = 1:12, month.abb) # Convert to abbreviated months\r\nmet.month = cbind(Month, met)\r\n\r\np1 = ggplot(met.month, aes(Month, OutTemp))\r\np2 = p1 + geom_jitter(position = position_jitter(w=0.15, h=0),\r\n     alpha=I(0.1), aes(colour=(Temp scale_colour_manual(values=c(&quot;#ff9999&quot;, \r\n     &quot;#9999ff&quot;))+ geom_boxplot(fill=&quot;#dddddd&quot;, alpha=I(0.5), aes(line=Month),\r\n     outlier.size=1, outlier.colour=&quot;#BBBBBB&quot;, colour=&quot;#666666&quot;) +\r\n     scale_y_continuous(name=&quot;Temperature (\u00b0F)&quot;)+\r\n     opts(legend.position=&quot;none&quot;,\r\n     title=&quot;Waterville Meteorological Data Summary for 2010&quot;)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/02\/Waterville_month_Temp.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/02\/Waterville_month_Temp.png\" alt=\"\" width=\"330\" height=\"240\" \/><\/a><\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n# Plot hourly temperatures\r\nhour.day = function(x){as.POSIXlt(x)$hour+1}\r\nhour = hour.day(met$date)\r\nmet.hour = cbind(hour,met)\r\n#\r\nl1 = ggplot(met.hour, aes(as.factor(hour), Temp))\r\nl2 = l1+geom_jitter(position=position_jitter(w=0.15, h=0),\r\nalpha = I(0.1), aes(colour=(Temp&lt;32)))+\r\n        scale_colour_manual(values=c(&quot;#ff9999&quot;, &quot;#9999ff&quot;))+\r\n        geom_boxplot(fill=&quot;#dddddd&quot;, alpha=I(0.5), aes(line=hour),\r\n        outlier.size=1, outlier.colour=&quot;#BBBBBB&quot;,\r\n        colour=&quot;#666666&quot;)+\r\n        scale_y_continuous(name=&quot;Temperature (\u00b0F)&quot;)+\r\n        scale_x_discrete(name=&quot;Hour of day (EST)&quot;)+\r\n        opts(legend.position=&quot;none&quot;,\r\n        title=&quot;Waterville Meteorological Data Summary for 2010&quot;)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/02\/Waterville_hourly_Temp.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/02\/Waterville_hourly_Temp-300x218.png\" alt=\"\" width=\"300\" height=\"218\" \/><\/a><\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n# Plot hourly temperatures by month\r\nmet.hour.month = cbind(hour,met.month)\r\n#\r\nm1 = ggplot(met.hour.month, aes(as.factor(hour), Temp))\r\nm2 = m1+geom_jitter(position=position_jitter(w=0.15, h=0), size=1,\r\nalpha = I(0.7), aes(colour=(Temp&lt;32)))+\r\n        scale_colour_manual(values=c(&quot;#ff9999&quot;, &quot;#9999ff&quot;))+\r\n        facet_wrap(~Month,ncol=3)+\r\n        geom_boxplot(fill=&quot;#dddddd&quot;, alpha=I(0.5), aes(line=hour),\r\n        outlier.size=0, outlier.colour=&quot;#BBBBBB&quot;,\r\n        colour=&quot;#666666&quot;)+\r\n        scale_y_continuous(name=&quot;Temperature (\u00b0F)&quot;)+\r\n        scale_x_discrete(name=&quot;Hour of day (EST)&quot;, breaks=c(6,12,18),\r\n        labels=c(6,12,18))+\r\n        opts(legend.position=&quot;none&quot;,\r\n        title=&quot;Waterville Meteorological Data Summary for 2010&quot;)\r\n<\/pre>\n<p><a href=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/02\/Waterville_time_month_Temp.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/web.colby.edu\/mgimond\/files\/2011\/02\/Waterville_time_month_Temp-218x300.png\" alt=\"\" width=\"218\" height=\"300\" \/><\/a><\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n#Save plots to png files\r\nggsave(&quot;Waterville_month_Temp.png&quot;, plot=p2, width=11, height=8)\r\nggsave(&quot;Waterville_hourly_Temp.png&quot;, plot=l2, width=11, height=8)\r\nggsave(&quot;Waterville_time_month_Temp.png&quot;, plot=m2, width=8, height=11)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Dowload data for this exercise here:Waterville meteorological data for 2010<\/p>\n","protected":false},"author":1199,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[12807],"tags":[],"_links":{"self":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/129"}],"collection":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/users\/1199"}],"replies":[{"embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/comments?post=129"}],"version-history":[{"count":37,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"predecessor-version":[{"id":167,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/posts\/129\/revisions\/167"}],"wp:attachment":[{"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web.colby.edu\/mgimond\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}