Tips for great graphics

R is a great program for generating top-notch graphics. But to get the best out of it, you need to put in a little more work. Here are a few tips for adapting your R graphics to make them look a little better. 1) Dont use the “File/Save as…/” menu. If you set up your graphic in the first place then theres no need to post-process (eg crop, scale etc) the graphic in other software. Use the graphic devices (jpeg(), tiff(), postscript(), etc), set your height and width to whatever you want the finished product to be and then create the graph. tiff(“~/Manuscript/Figs/Fig1.tiff”, width =2, height =2, units =”in”, res = 600) plot(dist ~ speed, cars) # cars is a base R dataset – data(cars) dev.off() The first argument to a graphic device such as tiff or jpeg is the…
Original Post: Tips for great graphics

WVPlots now at version 1.0.0 on CRAN!

Nina Zumel and I have been working on packaging our favorite graphing techniques in a more reusable way that emphasizes the analysis task at hand over the steps needed to produce a good visualization. We are excited to announce the WVPlots is now at version 1.0.0 on CRAN! The idea is: we sacrifice some of the flexibility and composability inherent to ggplot2 in R for a menu of prescribed presentation solutions. This is a package to produce plots while you are in the middle of another task. For example the plot below showing both an observed discrete empirical distribution (as stems) and a matching theoretical distribution (as bars) is a built in “one liner.” set.seed(52523) d <- data.frame(wt=100*rnorm(100)) WVPlots::PlotDistCountNormal(d,’wt’,’example’) The graph above is actually the product of a number of presentation decisions: Using a discrete histogram approach to summarize data…
Original Post: WVPlots now at version 1.0.0 on CRAN!

Because it's Friday: Bad road

Sometimes I think the potholes in the roads in Chicago are bad, but then a road like this puts things into perspective: (Thanks to TH for the link.) Don’t miss the shots looking back near the end to see how many people are in that vehicle! That’s all from the blog for this week. Have a great weekend, and we’ll be back after the US holiday on Monday. Enjoy!
Original Post: Because it's Friday: Bad road

Reflections on the ROpenSci Unconference

I had an amazing time this week participating in the 2018 ROpenSci Unconference, the sixth annual ROpenSci hackathon bringing together people to advance the tools and community for scientific computing with R. It was so inspiring to be among such a talented and dedicated group of people — special kudos goes to the organizing committee for curating such a great crowd. (I heard there were over 200 hundred nominations from which the 65 or so attendees were selected.) The idea behind the unconference is to spend two full days hacking on projects of interest to the community. Before the conference begins, the participants suggest projects as Github issues and begin discussions there. On the first day of the conference (after an icebreaker), the participants vote for projects they’d be interested in working on, and then form up into groups of 2-6 people or so…
Original Post: Reflections on the ROpenSci Unconference

Reflections on the ROpenSci Unconference

I had an amazing time this week participating in the 2018 ROpenSci Unconference, the sixth annual ROpenSci hackathon bringing together people to advance the tools and community for scientific computing with R. It was so inspiring to be among such a talented and dedicated group of people — special kudos goes to the organizing committee for curating such a great crowd. (I heard there were over 200 hundred nominations from which the 65 or so attendees were selected.)The idea behind the unconference is to spend two full days hacking on projects of interest to the community. Before the conference begins, the participants suggest projects as Github issues and begin discussions there. On the first day of the conference (after an icebreaker), the participants vote for projects they’d be interested in working on, and then form up into groups of 2-6 people or so to…
Original Post: Reflections on the ROpenSci Unconference

How to plot with patchwork

INTRODUCTION The goal of patchwork is to make it simple to combine separate ggplots into the same graphic. As such it tries to solve the same problem as gridExtra::grid.arrange() and cowplot::plot_grid but using an API that incites exploration and iteration. InstallationYou can install patchwork from github with: # install.packages(“devtools”)devtools::install_github(“thomasp85/patchwork”) The usage of patchwork is simple: just add plots together! library(ggplot2)library(patchwork) p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))p2 <- ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) p1 + p2 you are of course free to also add the plots together as part of the same plotting operation: ggplot(mtcars) +geom_point(aes(mpg, disp)) +ggplot(mtcars) +geom_boxplot(aes(gear, disp, group = gear)) layouts can be specified by adding a plot_layout() call to the assemble. This lets you define the dimensions of the grid and how much space to allocate to the different rows and columns p1 + p2…
Original Post: How to plot with patchwork

Programmatically creating text output in R – Exercises

In the age of Rmarkdown and Shiny, or when making any custom output from your data you want your output to look consistent and neat. Also, when writing your output you often want it to obtain a specific (decorative) format defined by the html or LaTeX engine. These exercises are an opportunity to refresh our memory on functions such as paste, sprintf, formatC and others that are convenient tools to achieve these ends. All of the solutions rely partly on the ultra flexible sprintf() but there are no-doubt many ways to solve the exercises with other functions, feel free to share your solutions in the comment section. Example solutions are available here. Exercise 1 Print out the following vector as prices in dollars (to the nearest cent):c(14.3409087337707, 13.0648270623048, 3.58504267621646, 18.5077076398145,16.8279241011882). Example: $14.34 Exercise 2 Using these numbers c(25, 7, 90,…
Original Post: Programmatically creating text output in R – Exercises

Slopegraphs and R – A pleasant diversion – May 26, 2018

I try to at least scan the R-bloggersfeed everyday. Not every article is of interest to me, but I often haveone of two different reactions to at least one article. Sometimes it isan “ah ha” moment because the article is right on point for a problemI have now or have had in the past and the article provides a (better)solution. Other times my reaction is more of an “oh yeah”, because itis something I have been meaning to investigate, or something I onceknew, but the article brings a different perspective to it. The second case happened to me this week. I’ve been aware of slopegraphsand bumpcharts for quite some time, and I certainly am aware of Tufte’swork. As an amateur militaryhistorian I’ve always loved, for example, hisposter depicting Napoleon’sRussian Campaign. So when I saw the article from MurtazaHaider titled“Edward Tufte’s…
Original Post: Slopegraphs and R – A pleasant diversion – May 26, 2018

vcr: record and replay HTTP requests

R package test suites that include HTTP requests are dependent on an internet connection being up, the internet connection speed, changing behavior of the remote server, as well as changing response formats/data from a remote server. We ideally want to test functionality of our package relative to some known data that isn’t intermittently unavailable or changing. Caveat is that we do want to make sure the package fails well, including fails well in response to server failures, but these responses can be cached. One way to deal with the problems above is to store responses from HTTP requests and use them in subsequent requests so that test suites are using a predictable set of data on each run of the test suite. We don’t have to reinvent the wheel to look for a solution, and the solution has been around…
Original Post: vcr: record and replay HTTP requests

Safe Disposal of Unexploded WWII Bombs

Abstract Unexploded WWII bombs are ticking threats despite being dropped more than 70 years ago. In this post we explain how statistical methods are used to plan the search and disposal of unexploded WWII bombs. In particular we consider and exemplify the non-parametric nearest neighbour distance (NND) method implemented in the R package highriskzone. The method analyses the spatial pattern of exploded bombs to determine so called risk-zones, that is regions with a high likelihood of containing unexploded bombs. The coverage of such risk-zones is investigated through both non-parametric and parametric point process simulation. NCAP aerial photo from 1944 showing the bombing of the V2 rocket facility at Peenemünde, Germany. Image is available under a custom NCAP license – higher resolution images are available from NCAP. This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. The markdown+Rknitr…
Original Post: Safe Disposal of Unexploded WWII Bombs