The plots thicken

February 7, 2018
By

(This article was first published on R – thinkr, and kindly contributed to R-bloggers)

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 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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

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)