Site icon R-bloggers

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:

< !-- iframe plugin v.4.3 wordpress.org/plugins/iframe/ -->

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

 PackagesFunctions
purrrmap_df
profvisprofvis
pageviewsarticle_pageviews
rvestread_html; html_nodes; html_text
dplyrmutate; select;
stringrstr_replace_all
lubridateymd
tibbledata_frame
ggplot2geom_line; geom_smooth; facet_wrap
ggthemestheme_economist; economist_pal
shinyfluidPage; reactive; renderPlot; shinyApp; selectInput; wellPanel; helpText; selectizeInput; titlePanel; mainPanel; plotOutput
shinythemesshinytheme
< !-- #tablepress-10 from cache -->

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 http://www.R-project.org.

 

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.

R-bloggers.com 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.