<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by jwalkeratheart on Medium]]></title>
        <description><![CDATA[Stories by jwalkeratheart on Medium]]></description>
        <link>https://medium.com/@jwalkeratheart?source=rss-bd7fa58ae41b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7yAh_JjV9QjcvZ-A.</url>
            <title>Stories by jwalkeratheart on Medium</title>
            <link>https://medium.com/@jwalkeratheart?source=rss-bd7fa58ae41b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 04:15:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jwalkeratheart/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ggplot2: Making a Beautiful Map in R!]]></title>
            <link>https://medium.com/@jwalkeratheart/ggplot2-making-a-beautiful-map-in-r-3b569c3f5342?source=rss-bd7fa58ae41b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b569c3f5342</guid>
            <dc:creator><![CDATA[jwalkeratheart]]></dc:creator>
            <pubDate>Sat, 08 Dec 2018 07:54:27 GMT</pubDate>
            <atom:updated>2018-12-08T08:35:04.014Z</atom:updated>
            <content:encoded><![CDATA[<p>In my class <strong>INFO 201: Technical Foundations</strong> this quarter, I have been learning to code in R through project-based assignments.</p><p>In my first team project of the year, we collaborated on making an interactive report in RMarkdown — part of which that looked something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*iAf4CCaNvPVL__LxDBIcwg.png" /><figcaption>Above is our frequency map of UFO sightings for the dataset that we used!</figcaption></figure><p>Using the data on UFO sighting reports, we were able to produce visualizations of the data that were embedded within the Markdown document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D2dnOYMXRm8K9diksJ6llw.png" /><figcaption>Here is a second visualization that we did, that shows the most common UFO sighting shapes on a bar graph.</figcaption></figure><p>Today, in this tutorial, I will give a brief overview of how I created the map that you saw above!</p><p>To begin, I used the <a href="https://cran.r-project.org/web/packages/ggplot2/index.html">ggplot2</a> package in R, which allows for clean data visualizations.</p><p>Make sure to source this library at the beginning of your code, as shown below, to ensure that it will be used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*PNlF3EZmfeT5ZEBGIsQryw.png" /></figure><p>Once you have your data filtered the way you want it, all you have to do it start with a simple line of code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/1*N7aAjKJJJObLmkKeXMuukA.png" /></figure><p>This essentially creates a <em>blank canvas</em> for whatever you would like to plot!</p><p>Next, to get the plot looking more like a map, we’re going to use the handy built-in R function of <a href="https://www.rdocumentation.org/packages/ggplot2/versions/3.1.0/topics/map_data">map_data()</a>, which returns a data frame containing information for the map you’d like. In this case, we’ll be using one of the United States!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*Lw6MhsfbarMNlGX20D074w.png" /></figure><h4>So, <strong>how do we get the map data onto the ggplot?</strong></h4><p>This can be done by using this state data to fill in a polygon shape on our plot!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*bg5QSeAkBeh12TDZku9l9g.png" /></figure><blockquote>Make sure to use the “+” operator to add new layers to your ggplot.</blockquote><p>While this may seem overwhelming, let’s break down what each variable means.</p><p><strong>data = states</strong> →</p><ul><li>This is telling ggplot to use our state map data as a base.</li></ul><p><strong>x = long, y =lat</strong>→</p><ul><li>This tells ggplot to use the United States longitude and latitude as mapping points.</li></ul><p><strong>fill = region, group = group →</strong></p><ul><li>This makes each region — in this case, each state of the U.S. — individually filled.</li></ul><p><strong>color = “white”, fill= “grey” →</strong></p><ul><li>Aesthetic choices that make the boundaries of the states white, and the overall fill color of the map grey.</li></ul><h4>This code results in this beautiful map of the United States!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*bWpsLRbAup0Nsm19I7KKLA.png" /><figcaption>The map we just made!</figcaption></figure><h4>Now, how can we put points on this map?</h4><p>We’ve made a beautiful U.S. map, but the next step is to place some points based on where UFO sightings were reported in our data.</p><p>Luckily, the handy function <a href="https://ggplot2.tidyverse.org/reference/geom_point.html">geom_point()</a> allows us to place points on our ggplot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*vPPSPoFysmcIoqybR4JL_A.png" /></figure><p><strong>data = ufo_data_continental_usa →</strong></p><ul><li>This tells ggplot to use our filtered UFO data for this plotting.</li></ul><p><strong>mapping = aes (x = lng, y = lat) →</strong></p><ul><li>Once again, we want our x values to be longitude, and y values to be latitude so that it appears like a map!</li></ul><p><strong>color = “green”, size = 1 →</strong></p><ul><li>This makes the points size 1 and in the color green.</li></ul><p>This rather simple line of code is just placing points on the latitudes and longitudes (x axis points and y axis points) that are already recorded in the data!</p><p>By adding this on to our previous ggplot code (again, don’t forget to use the “+” operator), we get this!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*UAVEdOzE-297ZpifoGhYbw.png" /><figcaption>A great map of the U.S. with UFO sighting points.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*vRzLnXeKbuYbyy_lc3vang.png" /><figcaption>The final code for the map we just made.</figcaption></figure><h3>Aesthetic Changes</h3><p>Now that you know how to create a U.S. map and plot points on it in ggplot, you can play around with different options and data sets!</p><p>For example, by changing “color = purple” and “size = 5” in our geom_point layer, we can change the look of the map:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*UTPRgA_Q-K6FWufJDunTWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*t6jowOeFbNoKRTDcs9mpNA.png" /><figcaption>The map has a whole new look!</figcaption></figure><p>Good luck on your R and ggplot journeys, and remember to explore and have fun with your project!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*c8DkLocaU1twlKR_BlMO8w.gif" /><figcaption>So many possibilities — just have fun with it!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b569c3f5342" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>