<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>R on zachcp</title>
		<link>http://zachcp.org/categories/r/</link>
		<description>Recent content in R on zachcp</description>
		<generator>Hugo</generator>
		<language>en-us</language>
		
		
		
			<copyright>© 2007- {year}</copyright>
		
		
			<lastBuildDate>Mon, 16 May 2016 08:03:00 +0000</lastBuildDate>
		
			<atom:link href="http://zachcp.org/categories/r/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>plotting images by extending ggplot</title>
				<link>http://zachcp.org/blog/geom_image_repel/</link>
				<pubDate>Mon, 16 May 2016 08:03:00 +0000</pubDate>
				<guid>http://zachcp.org/blog/geom_image_repel/</guid>
				<description>&lt;p&gt;As a followup to a recent post on the use of &lt;a href=&#34;http://zachcp.org/blog/2016/ggrepelmaps/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ggrepel&amp;rsquo;s placement code&lt;/a&gt; to&#xA;place images on maps, I wanted to do a better job of hooking into ggplot&amp;rsquo;s extensibility mechanism. In order to benefit from ggplot&amp;rsquo;s handling of variables I really wanted to have a column where I could add ggplot object. Then my imageGrobs could be passed around like any other value. That is not possible. However, it is possible to use&#xA;strings corresponding to image file locations. How hard would it be to modify the excellent &lt;a href=&#34;https://github.com/slowkow/ggrepel&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ggrepel&lt;/a&gt; package to support handling of images? Fortunately, as Kamil has done all of the hard work, the answer is: not very. Below I outline the basic workings of a ggplot &lt;strong&gt;geom&lt;/strong&gt; that lets you use filenames to plot PNGs into your ggplot. Gist of the code is &lt;a href=&#34;https://gist.github.com/zachcp/a82c017e52627bb2ab4651968bddf77e&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;here&lt;/a&gt;. To use this code you will need the geom_point_repel branch of my &lt;a href=&#34;https://github.com/zachcp/ggrepel&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ggrepel fork&lt;/a&gt;.&lt;/p&gt;</description>
			</item>
			<item>
				<title>ggrepel with maps</title>
				<link>http://zachcp.org/blog/ggrepelmaps/</link>
				<pubDate>Tue, 01 Mar 2016 08:03:00 +0000</pubDate>
				<guid>http://zachcp.org/blog/ggrepelmaps/</guid>
				<description>&lt;p&gt;&lt;a href=&#34;https://github.com/slowkow/ggrepel&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ggrepel&lt;/a&gt; is a package for R that build on ggplot an uses the&#xA;new ggproto OO system for extending ggplot to provide a few new geom&amp;rsquo;s for placing text and labels. Its great.&#xA;I&amp;rsquo;ve been working on some maps and was hoping I could take the same principles used in ggrepel&#xA;to add images to a ggplot. In short, I couldn&amp;rsquo;t find a way that would let you use the ggproto&#xA;system (unless there is a way to store grobs within data.frames that I don&amp;rsquo;t know about) but&#xA;you can call ggrepel directly to find non-overlapping points for arbitrary boxes, and you can&#xA;add plots, images etc to a grid grapchic using the &lt;strong&gt;annotation_custom&lt;/strong&gt; function of ggplot.&lt;/p&gt;</description>
			</item>
			<item>
				<title>NYC Boundary Maps</title>
				<link>http://zachcp.org/blog/nyc_borough_boundaries/</link>
				<pubDate>Mon, 01 Feb 2016 08:03:00 +0000</pubDate>
				<guid>http://zachcp.org/blog/nyc_borough_boundaries/</guid>
				<description>&lt;p&gt;I created an R package to load NYC Borough boundaries that is available on &lt;a href=&#34;https://github.com/zachcp/nycmaps&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;github&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code class=&#34;language-{r}&#34;&gt;#load and use the map&#xA;devtools::install_github(&amp;quot;zachcp/nycmaps&amp;quot;)&#xA;libary(nycmaps)&#xA;library(maps)&#xA;map(database=&amp;quot;nyc&amp;quot;)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;img src=&#34;http://zachcp.org/pics/blog/2016/nyc_boroughs.png&#34; width=500&gt;&#xA;&lt;h2 id=&#34;a-few-notes&#34;&gt;A few notes&lt;a class=&#34;anchor&#34; href=&#34;#a-few-notes&#34; aria-label=&#34;Link to this section&#34;&gt;#&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;check the &lt;code&gt;data-raw&lt;/code&gt; directory for a Makefile on Downloading and converting the geojson into the R-binary format&lt;/li&gt;&#xA;&lt;li&gt;Most regions/islands have been names but I may be missing some.&lt;/li&gt;&#xA;&lt;li&gt;Many of the Jamaica Bay Islands are not included (I took them all out and then added back the big ones around Cross Bay Boulevard)&lt;/li&gt;&#xA;&lt;li&gt;when loading this sets a /GlobalEnd defining where the map files live. To be incorporated in &lt;code&gt;Maps&lt;/code&gt; or included in CRAN this is a no-no but I don&amp;rsquo;t a better way.&lt;/li&gt;&#xA;&lt;/ol&gt;</description>
			</item>
			<item>
				<title>standard evaluation in dplyr</title>
				<link>http://zachcp.org/blog/programming_with_dplyr/</link>
				<pubDate>Tue, 02 Dec 2014 08:03:00 +0000</pubDate>
				<guid>http://zachcp.org/blog/programming_with_dplyr/</guid>
				<description>&lt;p&gt;A bunch of my data analyses in the past few months had been using R to analyze large data frames. I was excited when &lt;a href=&#34;https://github.com/hadley&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Hadley&lt;/a&gt; and &lt;a href=&#34;https://github.com/romainfrancois&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Romaine&lt;/a&gt; released &lt;a href=&#34;https://github.com/hadley/dplyr&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;dplyr&lt;/a&gt;, their high performance package for dataframe analysis/manipulation. Although the performance is awesome, I think dplyr also excels in making it much easier to write R code and compose usefulf funcitons form a set of simple functions the call &amp;ldquo;verbs&amp;rdquo;.&lt;/p&gt;&#xA;&lt;p&gt;Despite having used R a fair bit I almost always need to google/stack-overflow simple things related to the grammar of R. Subsetting, renaming, etc are not at all intuitive and I think this is part of the reasons why it is easier to pick up python/pandas due to the rather straightforward syntax. So dplyr&amp;rsquo;s straight-forward syntax of a small number of well defined &amp;ldquo;verbs&amp;rdquo; and its use of the piping operator &lt;code&gt;%&amp;gt;%&lt;/code&gt; make it an excellent choice for use in data analysis. However, there was one issue when I was using dplyr that was a bit problematic: although performing a dplyr-based data analysis pipeline was straight-forward, composing a function to do that analysis was impossible&amp;hellip;&amp;hellip;. until now.&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
