<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/new-ibm-plex-sans-support-in-hrbrthemes-automating-axis-text-justification/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2017/11/16/new-ibm-plex-sans-support-in-hrbrthemes-automating-axis-text-justification/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>IBM has a <a rel="nofollow" href="https://ibm.github.io/type/" target="_blank">new set of corporate typefaces</a> — dubbed “Plex” — and has released them with a generous open license. IBM Plex Sans is not too shabby:</p>
<p><a rel="nofollow" href="https://i2.wp.com/rud.is/b/wp-content/uploads/2017/11/IBM_Plex_Font_Free_by_IBM_%C2%BB_Font_Squirrel.png?ssl=1" target="_blank"><img alt="" src="https://i2.wp.com/rud.is/b/wp-content/uploads/2017/11/IBM_Plex_Font_Free_by_IBM_%C2%BB_Font_Squirrel.png?resize=780%2C800&ssl=1" class="wp-image-7139" data-recalc-dims="1"></a></p>
<p>(that image was grifted from a Font Squirrel preview page)</p>
<p>The digit glyphs are especially nice for charts and the font iself is <em>just different enough</em> from Helvetica that I felt it was worth including in <a rel="nofollow" href="https://github.com/hrbrmstr/hrbrthemes" target="_blank"><code>hrbrthemes</code><img alt="🔗" src="https://i1.wp.com/s.w.org/images/core/emoji/2.3/72x72/1f517.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></a>. I converted the fonts to TTF (for best compatibility with R ‘stuff’), added them to the package (so you can install them from there), cloned the other ipsum functions into <code>_ps</code> versions and tried to figure out the best fonts for various theme elements. Here’s the result so far:</p>
<p><a rel="nofollow" href="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/11/README-unnamed-chunk-7-1.png?ssl=1" target="_blank"><img alt="" src="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/11/README-unnamed-chunk-7-1.png?resize=780%2C546&ssl=1" class="wp-image-7140" data-recalc-dims="1"></a></p>
<p>(I <em>really</em> like those digits.)</p>
<p>I haven’t tried <code>theme_ipsum_ps()</code> on anything but macOS, so if you kick the tyres and encounter problems, please <a rel="nofollow" href="https://github.com/hrbrmstr/hrbrthemes/issues" target="_blank">file an issue</a>. </p>
<h3>Flushing ticks’ text</h3>
<p>Readers with keen eyes will see that the axis text labels have different <code>hjust</code> settings on the ends (vs the <code>0.5</code> in the inner ones. I don’t always set them that was as it is not always appropriate to do so (IMO). When I do, it’s usually been a “figure out the breaks and then hand-craft the <code>theme()</code> components” endeavour. Well, not anymore (at least in simple cases) thanks to the new <code>flush_ticks()</code> </p>
<p>It’s a dead-simple process but it requires knowing the breaks and you pretty much have to build the plot to do that, so the function takes your completed ggplot2 object, introspects it (post-temporary build) and sets the tick text justification in the style seen in the above image. The code below generates that image and demonstrates use of <code>flush_ticks()</code>:</p>
<pre><code>library(hrbrthemes)
library(ggplot2)

ggplot(mpg, aes(displ, hwy)) +
  geom_jitter(aes(color=class, fill=class), size=3, shape=21, alpha=1/2) +
  scale_x_continuous(expand=c(0,0), limits=c(1, 8), breaks=1:8) +
  scale_y_continuous(expand=c(0,0), limits=c(10, 50)) +
  scale_color_ipsum() +
  scale_fill_ipsum() +
  facet_wrap(~class, scales=&quot;free&quot;) +
  labs(
    title=&quot;IBM Plex Sans Test&quot;,
    subtitle=&quot;This is a subtitle to see the how it looks in IBM Plex Sans&quot;,
    caption=&quot;Source: hrbrthemes &amp; IBM&quot;
  ) +
  theme_ipsum_ps(grid=&quot;XY&quot;, axis=&quot;xy&quot;) +
  theme(legend.position=&quot;none&quot;) -> gg

flush_ticks(gg)</code></pre>
<p>As indicated, this won’t presently work for free-scales but it’s going to save me a few minutes for each plot I would have done the more manual way. But, releasing it into the wild will help catch edge cases I haven’t considered yet. In the coming weeks, <strike>I’m going to add</strike> I’ve added an option to <code>flush_ticks()</code> to generate <code>theme(axis.text...)</code> statements vs just return the plot so you can include the <code>theme()</code> code directly vs have to rely on the function to display the plot. I may even make it an RStudio addin (though folks who would like to do that are encouraged to submit a PR).</p>
<p>I hope both new <code>hrbrthemes</code> features are useful to folks and they should be on CRAN in mid-December with an R markdown set of themes to go with the package.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rud.is/b/2017/11/16/new-ibm-plex-sans-support-in-hrbrthemes-automating-axis-text-justification/"> R – rud.is</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/LGbKlmTxpeY" height="1"></a></div>