{"id":170,"date":"2021-12-09T11:45:04","date_gmt":"2021-12-09T16:45:04","guid":{"rendered":"https:\/\/sites.owu.edu\/geog-199\/?p=170"},"modified":"2021-12-09T11:45:04","modified_gmt":"2021-12-09T16:45:04","slug":"frawley-r-geospatial-wrap-up","status":"publish","type":"post","link":"https:\/\/sites.owu.edu\/geog-293\/2021\/12\/09\/frawley-r-geospatial-wrap-up\/","title":{"rendered":"Frawley: R Geospatial Wrap Up"},"content":{"rendered":"<p><b>Background<\/b><span style=\"font-weight: 400\"> \u2014\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">This independent study was more so learning R rather than spending more time in project-based learning as I did with python. R is a very powerful data-driven language and is great for using large data sets. R is vastly used for geospatial analysis as well. I created a county population map of the United States using census data from built-in libraries whose primary use is for geospatial analysis. The code looks very simple, but it was not. I had significantly more problems with R than I did with Python. The syntax used in R is an absolute cluster and I despise it.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Steps\u00a0<\/b><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Import libraries usmap and ggplot2.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Add some data to plot the map, data = countypop draws the county lines and values creates data with the built-in census data via a CSV.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Create a scale and create breaks\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Change the scale fill to one that\u2019s not a constant color for easier viewing<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Cry because you can\u2019t create an interactive map with tmap\u00a0<\/span><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><b>The Code<\/b><span style=\"font-weight: 400\"> \u2014\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">library(usmap)<\/span><\/p>\n<p><span style=\"font-weight: 400\">library(ggplot2)<\/span><\/p>\n<p><span style=\"font-weight: 400\">plot_usmap(data = countypop, values = &#8220;pop_2015&#8221;, color = &#8220;grey&#8221;)<\/span><span style=\"font-weight: 400\"> +\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0<\/span><span style=\"font-weight: 400\">\u00a0scale_fill_viridis_c<\/span><span style=\"font-weight: 400\">(<\/span><span style=\"font-weight: 400\">name = &#8220;County Population 2015&#8221;, label = scales::comma, option = &#8216;D&#8217;, trans = &#8220;log2&#8221;,\u00a0 breaks = trans_breaks(&#8220;log2&#8221;, function(x) 2^x))+<\/span><\/p>\n<p><span style=\"font-weight: 400\">theme(legend.position = &#8220;right&#8221;)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-171 aligncenter\" src=\"https:\/\/sites.owu.edu\/geog-199\/wp-content\/uploads\/sites\/189\/2021\/12\/countypop-300x254.png\" alt=\"\" width=\"570\" height=\"482\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><b>Problems <\/b><span style=\"font-weight: 400\">\u2014\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Like I stated before, I had tons of issues with this project. I programmed the map at least 15 different ways and it never looked like how I wanted it to. I think R is a little over my head when it comes to the math-based stuff like the scale. The breaks were never how I wanted them but I chose one that seemed the most reasonable.<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0Another issue that I had was this map is a static map, it cannot move and you cannot click on counties to see their population. I tried for at least three weeks to create an interactive map through the library T map. It\u2019s literally very simple, you just join the counties and the county population CSV to create the interactive map. The issue that I had was joining the two tables by their geoID. It never seemed to work and I literally even created my own spreadsheet with the counties\u2019 populations, names, states, and geoID. Didn\u2019t work. This was the most frustrating part of the project that I dealt with.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Again, I took more of a book approach to this course so it definitely felt like I could\u2019ve figured it out by making other things within R. I can follow the code and see what someone is doing, but trying to do it on your own starting out is very difficult. Also, R is just way worse and not as user-friendly as Python. I feel that I could definitely become better at R if I just spent more time with it, and also brushed up on my math skills a little more.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background \u2014\u00a0 This independent study was more so learning R rather than spending more time in project-based learning as I did with python. R is a very powerful data-driven language and is great for using large data sets. R is <span class=\"readmore\"><a href=\"https:\/\/sites.owu.edu\/geog-293\/2021\/12\/09\/frawley-r-geospatial-wrap-up\/\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":1213,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/users\/1213"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":1,"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/posts\/170\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.owu.edu\/geog-293\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}