The plots thicken

[This article was first published on R – thinkr, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Every story needs a good plot

One could think of data science as “art, grounded in facts”. It tells a story through visualisation. Both story and visualisation rely on a good plot. And an abundance of those has evolved over time. Many have their own dedicated Wikipedia page!

Which generate the most interest? How is the interest in each trending over time? Try this app to find out.

The app may take a moment to load:

View full-width here.

Note the utility of selecting the right scaling. The combination of “fixed” and “normal” reveals what must have been “world histogram day” on July 27th 2015, but little else.

The need for speed

Turning non-interactive code into an app sharpens the mind’s focus on performance. And profvis, integrated into RStudio via the profile menu option, is a wonderful “tool for helping you understand how R spends its time”.

My first version of the app was finger-tappingly slow.

Profvis revealed the main culprit to be the pre-loading of a dataframe with the page-view data for all chart types (there are more than 100). Profiling prompted the more efficient “reactive” approach of loading the data only for the user’s selection (maximum of 8).

Profiling also showed that rounding the corners of the plot.background with additional grid-package code was expensive. App efficiency felt more important than minor cosmetic detailing. And most users would probably barely notice (had I not drawn attention to it here).

R toolkit

  Packages Functions
purrr map_df
profvis profvis
pageviews article_pageviews
rvest read_html; html_nodes; html_text
dplyr mutate; select;
stringr str_replace_all
lubridate ymd
tibble data_frame
ggplot2 geom_line; geom_smooth; facet_wrap
ggthemes theme_economist; economist_pal
shiny fluidPage; reactive; renderPlot; shinyApp; selectInput; wellPanel; helpText; selectizeInput; titlePanel; mainPanel; plotOutput
shinythemes shinytheme

View the code here.

Citations / Attributions

R Development Core Team (2008). R: A language and environment for
statistical computing. R Foundation for Statistical Computing,
Vienna, Austria. ISBN 3-900051-07-0, URL


The post The plots thicken appeared first on thinkr.

To leave a comment for the author, please follow the link and comment on their blog: R – thinkr. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)