

{"id":3043,"date":"2014-09-23T12:28:49","date_gmt":"2014-09-23T17:28:49","guid":{"rendered":"http:\/\/rud.is\/b\/?p=3043"},"modified":"2019-11-09T14:58:11","modified_gmt":"2019-11-09T19:58:11","slug":"seeing-the-daylight-with-r","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/","title":{"rendered":"Seeing the (day)light with R"},"content":{"rendered":"<p>The arrival of the autumnal <a href=\"http:\/\/en.wikipedia.org\/wiki\/Equinox\">equinox<\/a> foreshadows the reality of longer nights and shorter days here in the northeast US. We can both see that reality and distract ourselves from it at the same time by firing up RStudio (or your favorite editor) and taking a look at the sunrise &amp; sunset times based on our map coordinates using some functions from the R {maptools} package.<\/p>\n<p>The <code>sunriset<\/code> function takes in a lat\/lon pair, a range of dates and whether we want sunrise or sunset calculated and returns when those ephemeral events occur. For example, we can see the sunrise time for Portsmouth, NH on Christmas day this year (2014) via:<\/p>\n<pre><code class=\"language-r\">library(maptools)\n\n# these functions need the lat\/lon in an unusual format\nportsmouth &lt;- matrix(c(-70.762553, 43.071755), nrow=1)\nfor_date &lt;- as.POSIXct(\"2014-12-25\", tz=\"America\/New_York\")\nsunriset(portsmouth, for_date, direction=\"sunrise\", POSIXct.out=TRUE)\n\n##         day_frac                time\n## newlon 0.3007444 2014-12-25 07:13:04\n<\/code><\/pre>\n<p>We can pass in a vector of dates, to this function, and that means we&#8217;ll have data points we can work with to visualize this change. Let&#8217;s wrap the sequence generation into a function of our own and extract:<\/p>\n<ul>\n<li>sunrise<\/li>\n<li>sunset<\/li>\n<li>solar noon<\/li>\n<li># hours of daylight<\/li>\n<\/ul>\n<p>for every day in the sequence, returning the result as a data frame.<\/p>\n<pre><code class=\"language-r\"># adapted from http:\/\/r.789695.n4.nabble.com\/maptools-sunrise-sunset-function-td874148.html\nephemeris &lt;- function(lat, lon, date, span=1, tz=\"UTC\") {\n\n  # convert to the format we need\n  lon.lat &lt;- matrix(c(lon, lat), nrow=1)\n\n  # make our sequence - using noon gets us around daylight saving time issues\n  day &lt;- as.POSIXct(date, tz=tz)\n  sequence &lt;- seq(from=day, length.out=span , by=\"days\")\n\n  # get our data\n  sunrise &lt;- sunriset(lon.lat, sequence, direction=\"sunrise\", POSIXct.out=TRUE)\n  sunset &lt;- sunriset(lon.lat, sequence, direction=\"sunset\", POSIXct.out=TRUE)\n  solar_noon &lt;- solarnoon(lon.lat, sequence, POSIXct.out=TRUE)\n\n  # build a data frame from the vectors\n  data.frame(date=as.Date(sunrise$time),\n             sunrise=as.numeric(format(sunrise$time, \"%H%M\")),\n             solarnoon=as.numeric(format(solar_noon$time, \"%H%M\")),\n             sunset=as.numeric(format(sunset$time, \"%H%M\")),\n             day_length=as.numeric(sunset$time-sunrise$time))\n\n}\n<\/code><\/pre>\n<p>Now we can take a look at these values over 10 days near All Hallows Eve:<\/p>\n<pre><code class=\"language-r\">ephemeris(43.071755, -70.762553, \"2014-10-31\", 10, tz=\"America\/New_York\")\n\n##          date sunrise solarnoon sunset day_length\n## 1  2014-10-31     716      1226   1736  10.332477\n## 2  2014-11-01     717      1226   1734  10.289145\n## 3  2014-11-02     518      1026   1533  10.246169\n## 4  2014-11-03     620      1126   1632  10.203563\n## 5  2014-11-04     621      1126   1631  10.161346\n## 6  2014-11-05     622      1126   1629  10.119535\n## 7  2014-11-06     624      1126   1628  10.078148\n## 8  2014-11-07     625      1126   1627  10.037204\n## 9  2014-11-08     626      1126   1626   9.996721\n## 10 2014-11-09     627      1126   1625   9.956719\n<\/code><\/pre>\n<p>We now have everything we need to visualize the seasonal daylight changes. We&#8217;ll use <code>ggplot<\/code> (with some help from the <code>grid<\/code> package) and build a two panel graph, one that gives us a &#8220;ribbon&#8221; view of what hours of the day are in daylight and the other just showing the changes in the total number of hours of daylight available during the day. We&#8217;ll build the function so that it will:<\/p>\n<ul>\n<li>optionally show the current date\/time (<code>TRUE<\/code> by default)<\/li>\n<li>optionally show when solar noon is (<code>FALSE<\/code> by default)<\/li>\n<li>optionally plot the graphs (<code>TRUE<\/code> by default)<\/li>\n<li>return an <code>arrangeGrob<\/code> of the charts in the event we want to use them in other charts<\/li>\n<\/ul>\n<pre><code class=\"language-r\">library(ggplot2)\nlibrary(scales)\nlibrary(gridExtra)\n\n# create two formatter functions for the x-axis display\n\n# for graph #1 y-axis\ntime_format &lt;- function(hrmn) substr(sprintf(\"%04d\", hrmn),1,2)\n\n# for graph #2 y-axis\npad5 &lt;- function(num) sprintf(\"%2d\", num)\n\ndaylight &lt;- function(lat, lon, place, start_date, span=2, tz=\"UTC\", \n                     show_solar_noon=FALSE, show_now=TRUE, plot=TRUE) {\n\n  stopifnot(span&gt;=2) # really doesn't make much sense to plot 1 value\n\n  srss &lt;- ephemeris(lat, lon, start_date, span, tz)\n\n  x_label = \"\"\n\n  gg &lt;- ggplot(srss, aes(x=date))\n  gg &lt;- gg + geom_ribbon(aes(ymin=sunrise, ymax=sunset), fill=\"#ffeda0\")\n\n  if (show_solar_noon) gg &lt;- gg + geom_line(aes(y=solarnoon), color=\"#fd8d3c\")\n\n  if (show_now) {\n    gg &lt;- gg + geom_vline(xintercept=as.numeric(as.Date(Sys.time())), color=\"#800026\", linetype=\"longdash\", size=0.25)\n    gg &lt;- gg + geom_hline(yintercept=as.numeric(format(Sys.time(), \"%H%M\")), color=\"#800026\", linetype=\"longdash\", size=0.25)\n    x_label = sprintf(\"Current Date \/ Time: %s\", format(Sys.time(), \"%Y-%m-%d \/ %H:%M\"))\n  }\n\n  gg &lt;- gg + scale_x_date(expand=c(0,0), labels=date_format(\"%b '%y\"))\n  gg &lt;- gg + scale_y_continuous(labels=time_format, limits=c(0,2400), breaks=seq(0, 2400, 200), expand=c(0,0))\n  gg &lt;- gg + labs(x=x_label, y=\"\",\n                  title=sprintf(\"Sunrise\/set for %s\\n%s \", place, paste0(range(srss$date), sep=\" \", collapse=\"to \")))\n  gg &lt;- gg + theme_bw()\n  gg &lt;- gg + theme(panel.background=element_rect(fill=\"#525252\"))\n  gg &lt;- gg + theme(panel.grid=element_blank())\n\n  gg1 &lt;- ggplot(srss, aes(x=date, y=day_length))\n  gg1 &lt;- gg1 + geom_area(fill=\"#ffeda0\")\n  gg1 &lt;- gg1 + geom_line(color=\"#525252\")\n\n  if (show_now) gg1 &lt;- gg1 + geom_vline(xintercept=as.numeric(as.Date(Sys.time())), color=\"#800026\", linetype=\"longdash\", size=0.25)\n\n  gg1 &lt;- gg1 + scale_x_date(expand=c(0,0), labels=date_format(\"%b '%y\"))\n  gg1 &lt;- gg1 + scale_y_continuous(labels=pad5, limits=c(0,24), expand=c(0,0))\n  gg1 &lt;- gg1 + labs(x=\"\", y=\"\", title=\"Day(light) Length (hrs)\")\n  gg1 &lt;- gg1 + theme_bw()\n\n  if (plot) grid.arrange(gg, gg1, nrow=2)\n\n  arrangeGrob(gg, gg1, nrow=2)\n\n}\n<\/code><\/pre>\n<p>We can test our our new function using the same location and graph the sunlight data for a year starting September 1, 2014 (select graph for full-size version):<\/p>\n<pre><code class=\"language-r\">daylight(43.071755, -70.762553, \"Portsmouth, NH\", \"2014-09-01\", 365, tz=\"America\/New_York\")\n<\/code><\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3046\" data-permalink=\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/sunlight\/\" data-orig-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?fit=800%2C600&amp;ssl=1\" data-orig-size=\"800,600\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sunlight\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?fit=300%2C225&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?fit=510%2C382&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?resize=510%2C383&#038;ssl=1\" alt=\"sunlight\" width=\"510\" height=\"383\" class=\"aligncenter size-full wp-image-3046\" srcset=\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?w=800&amp;ssl=1 800w, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?resize=150%2C112&amp;ssl=1 150w, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?resize=300%2C225&amp;ssl=1 300w, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?resize=530%2C397&amp;ssl=1 530w, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?resize=535%2C401&amp;ssl=1 535w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><\/a><\/p>\n<p>With the longer nights approaching we can further enhance the plotting function to add markers for solstices and perhaps even make a new version that compares sunlight across different geographical locations.<\/p>\n<p>Complete code example is in <a href=\"https:\/\/gist.github.com\/hrbrmstr\/96b136bdfb74ffc258e2\">this gist<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The arrival of the autumnal equinox foreshadows the reality of longer nights and shorter days here in the northeast US. We can both see that reality and distract ourselves from it at the same time by firing up RStudio (or your favorite editor) and taking a look at the sunrise &amp; sunset times based on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[24,678,673,91,680],"tags":[810],"class_list":["post-3043","post","type-post","status-publish","format-standard","hentry","category-charts-graphs","category-data-visualization","category-datavis-2","category-r","category-weather","tag-post"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Seeing the (day)light with R - rud.is<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Seeing the (day)light with R - rud.is\" \/>\n<meta property=\"og:description\" content=\"The arrival of the autumnal equinox foreshadows the reality of longer nights and shorter days here in the northeast US. We can both see that reality and distract ourselves from it at the same time by firing up RStudio (or your favorite editor) and taking a look at the sunrise &amp; sunset times based on [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2014-09-23T17:28:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-09T19:58:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png\" \/>\n<meta name=\"author\" content=\"hrbrmstr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"hrbrmstr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Seeing the (day)light with R\",\"datePublished\":\"2014-09-23T17:28:49+00:00\",\"dateModified\":\"2019-11-09T19:58:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/\"},\"wordCount\":365,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886\"},\"image\":{\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png\",\"keywords\":[\"post\"],\"articleSection\":[\"Charts &amp; Graphs\",\"Data Visualization\",\"DataVis\",\"R\",\"Weather\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/\",\"url\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/\",\"name\":\"Seeing the (day)light with R - rud.is\",\"isPartOf\":{\"@id\":\"https:\/\/rud.is\/b\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png\",\"datePublished\":\"2014-09-23T17:28:49+00:00\",\"dateModified\":\"2019-11-09T19:58:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?fit=800%2C600&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?fit=800%2C600&ssl=1\",\"width\":800,\"height\":600},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/rud.is\/b\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Seeing the (day)light with R\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/rud.is\/b\/#website\",\"url\":\"https:\/\/rud.is\/b\/\",\"name\":\"rud.is\",\"description\":\"&quot;In God we trust. All others must bring data&quot;\",\"publisher\":{\"@id\":\"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/rud.is\/b\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886\",\"name\":\"hrbrmstr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1\",\"url\":\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1\",\"width\":460,\"height\":460,\"caption\":\"hrbrmstr\"},\"logo\":{\"@id\":\"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1\"},\"description\":\"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7\",\"sameAs\":[\"http:\/\/rud.is\"],\"url\":\"https:\/\/rud.is\/b\/author\/hrbrmstr\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Seeing the (day)light with R - rud.is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/","og_locale":"en_US","og_type":"article","og_title":"Seeing the (day)light with R - rud.is","og_description":"The arrival of the autumnal equinox foreshadows the reality of longer nights and shorter days here in the northeast US. We can both see that reality and distract ourselves from it at the same time by firing up RStudio (or your favorite editor) and taking a look at the sunrise &amp; sunset times based on [&hellip;]","og_url":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/","og_site_name":"rud.is","article_published_time":"2014-09-23T17:28:49+00:00","article_modified_time":"2019-11-09T19:58:11+00:00","og_image":[{"url":"https:\/\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png","type":"","width":"","height":""}],"author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Seeing the (day)light with R","datePublished":"2014-09-23T17:28:49+00:00","dateModified":"2019-11-09T19:58:11+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/"},"wordCount":365,"commentCount":4,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"image":{"@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png","keywords":["post"],"articleSection":["Charts &amp; Graphs","Data Visualization","DataVis","R","Weather"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/","url":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/","name":"Seeing the (day)light with R - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#primaryimage"},"image":{"@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#primaryimage"},"thumbnailUrl":"https:\/\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png","datePublished":"2014-09-23T17:28:49+00:00","dateModified":"2019-11-09T19:58:11+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#primaryimage","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?fit=800%2C600&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2014\/09\/sunlight.png?fit=800%2C600&ssl=1","width":800,"height":600},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2014\/09\/23\/seeing-the-daylight-with-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Seeing the (day)light with R"}]},{"@type":"WebSite","@id":"https:\/\/rud.is\/b\/#website","url":"https:\/\/rud.is\/b\/","name":"rud.is","description":"&quot;In God we trust. All others must bring data&quot;","publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rud.is\/b\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886","name":"hrbrmstr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","width":460,"height":460,"caption":"hrbrmstr"},"logo":{"@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1"},"description":"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7","sameAs":["http:\/\/rud.is"],"url":"https:\/\/rud.is\/b\/author\/hrbrmstr\/"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p23idr-N5","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":3929,"url":"https:\/\/rud.is\/b\/2016\/02\/11\/plot-the-new-svg-r-logo-with-ggplot2\/","url_meta":{"origin":3043,"position":0},"title":"Plot the new SVG R logo with ggplot2","author":"hrbrmstr","date":"2016-02-11","format":false,"excerpt":"High resolution and SVG versions of the new R logo are finally available. I converted the SVG to WKT (file here) which means we can use it like we would a shapefile in R. That includes plotting! Here's a short example of how to read that WKT and plot the\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/02\/RStudio.png?fit=1198%2C942&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1750,"url":"https:\/\/rud.is\/b\/2012\/10\/28\/watch-sandy-in-r-including-forecast-cone\/","url_meta":{"origin":3043,"position":1},"title":"Watch Sandy in &#8220;R&#8221; (Including Forecast Cone)","author":"hrbrmstr","date":"2012-10-28","format":false,"excerpt":"As indicated in the code comments, Google took down the cone KML files. I'll be changing the code to use the NHC archived cone files later tonight NOTE: There is significantly updated code on github for the Sandy 'R' dataviz. This is a follow-up post to the quickly crafted Watch\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2793,"url":"https:\/\/rud.is\/b\/2013\/11\/27\/mapping-power-outages-in-maine-with-r\/","url_meta":{"origin":3043,"position":2},"title":"Mapping Power Outages In Maine With R","author":"hrbrmstr","date":"2013-11-27","format":false,"excerpt":"UPDATE: A Shiny (dynamic) version of this is now available. We had yet-another power outage this morning due to the weird weather patterns of the week and it was the final catalyst I needed to crank out some R code to map the affected counties. Central Maine Power provides an\u2026","rel":"","context":"In &quot;Charts &amp; Graphs&quot;","block_context":{"text":"Charts &amp; Graphs","link":"https:\/\/rud.is\/b\/category\/charts-graphs\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/11\/Plot_Zoom.png?fit=530%2C680&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/11\/Plot_Zoom.png?fit=530%2C680&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2013\/11\/Plot_Zoom.png?fit=530%2C680&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":2685,"url":"https:\/\/rud.is\/b\/2013\/09\/19\/animated-irl-pirate-attacks-in-r\/","url_meta":{"origin":3043,"position":3},"title":"Animated IRL Pirate Attacks In R","author":"hrbrmstr","date":"2013-09-19","format":false,"excerpt":"Avast me hearRties! (ok, enough of the pirate speak in a blog post) It wouldn't be TLAPD without out some modest code & idea pilfering from Mark Bulling & Simon Raper. While those mateys did a fine job hoisting up some R code (your really didn't think I'd stop with\u2026","rel":"","context":"In &quot;DataVis&quot;","block_context":{"text":"DataVis","link":"https:\/\/rud.is\/b\/category\/datavis-2\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4217,"url":"https:\/\/rud.is\/b\/2016\/03\/29\/easier-composite-u-s-choropleths-with-albersusa\/","url_meta":{"origin":3043,"position":4},"title":"Easier Composite U.S. Choropleths with albersusa","author":"hrbrmstr","date":"2016-03-29","format":false,"excerpt":"Folks who've been tracking this blog on R-bloggers probably remember [this post](https:\/\/rud.is\/b\/2014\/11\/16\/moving-the-earth-well-alaska-hawaii-with-r\/) where I showed how to create a composite U.S. map with an Albers projection (which is commonly referred to as AlbersUSA these days thanks to D3). I'm not sure why I didn't think of this earlier, but you\u2026","rel":"","context":"In &quot;cartography&quot;","block_context":{"text":"cartography","link":"https:\/\/rud.is\/b\/category\/cartography\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2016\/03\/Fullscreen_3_29_16__9_06_AM.png?fit=1200%2C747&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3117,"url":"https:\/\/rud.is\/b\/2014\/11\/16\/moving-the-earth-well-alaska-hawaii-with-r\/","url_meta":{"origin":3043,"position":5},"title":"Moving The Earth (well, Alaska &#038; Hawaii) With R","author":"hrbrmstr","date":"2014-11-16","format":false,"excerpt":"In a previous post we looked at how to use D3 TopoJSON files with R and make some very D3-esque maps. I mentioned that one thing missing was moving Alaska & Hawaii a bit closer to the continental United States and this post shows you how to do that. The\u2026","rel":"","context":"In &quot;d3&quot;","block_context":{"text":"d3","link":"https:\/\/rud.is\/b\/category\/d3\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/3043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/comments?post=3043"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/3043\/revisions"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=3043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=3043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=3043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}