Customizable charts with R base graphics and Shiny

I’ve uploaded a new R Shiny web application. The app shows daily precipitation for different locations around Alaska as far back as 1950. Statisticians and useRs may find the app interesting because of its customization features for controlling the look and feel of the R base graphics used to produce a customizable chart. UseRs of the Shiny package may find the customized CSS of the app interesting as well. I went with a darker theme this time. And if you find historical Alaska daily precipitation interesting, there is of course that. The emphasis here is on customization. This app only begins to scratch the surface, but it represents a good first example of making various R base graphics plotting arguments, among other things, available to the useR via a Shiny app.

akDailyPrecipCustomCharts
Currently the app includes a variety of options: location selection, subsetting by year range, time series centering on a specific month depending on how you want to define/display a precipitation year, handling and display of missing data and setting monthly and annual missing data thresholds, whether to draw all of the marginal panel plots, color themes and gradients, and various options for rescaling relative circle size depending on the intra- and inter-annual variability in a location’s precipitation signal.

The latter can help make differences precipitation intensities stand out more or less and it is important to understand that this is all relative. It is common practice to let the size of points correspond monotonically to their values, using a log transformation of the data for example, just as it is to use no transformation at all. This is to help visually communicate an idea and draw attention to underlying patterns that may be harder to see on a linear scale. For those familiar with R, I allow for some recursive log transformations as well as some linear multipliers of plot arguments such as cex so that you have more control over the display on account of some locations having wildly different variability in historical daily precipitation intensities. What may look informative at one location may yield a less helpful plot for another location under the same graphical parameter settings.

Also, even with no transformations, circle size and color gradient are based on the data for the selected location, not across all locations. The latter would conveniently make relative intensity comparisons across plots of multiple locations possible. However, applying the scaling across datasets would wash out much of the color and size variation within datasets, making the graphics actually shown here less informative on an individual basis. When time permits, I would like to add a feature for plotting precipitation events for two selected places on one graph, where both datasets share a common color and size gradients for their data points. Lastly, the plots may take several seconds to load in the browser. Please be patient. I would like to speed up the code when I have some time by breaking much of the data manipulation code out of the final plotting command where it currently resides. This way, re-plotting can happen more quickly when changing aesthetic features as opposed to actually altering the selection of the underlying dataset or subset. Alas, there is not enough time in the day to deal with this yet…

This entry was posted by Matt Leonawicz.

6 thoughts on “Customizable charts with R base graphics and Shiny

  1. Gorgeous and overall great app! Just want to say that your posts + apps + codes have been very useful for me in doing up my Shiny app. Thanks and keep them coming!

    • Thanks for your feedback. It is much appreciated. I am glad to hear you have found the apps and posts informative. I have plans to expand upon and improve this particular app in the future, time permitting. Hopefully not too far in the future.
      Matt

      • Hi Matt,

        I am working on a forecasting apps using shiny. I am not getting the plot , but there is no error though.

        Let me know, if i can show my codes with you. let me know some insight.

        Ramesh

      • Hi Ramesh,

        I won’t have time to help you with exploring your code. However, the best place to direct those kinds of detailed questions and code debugging is the Shiny Google Group:
        https://groups.google.com/forum/#!forum/shiny-discuss
        You can search there for answers to similar questions that have already been addressed. If you don’t find what you are looking for, you can make a post there to get assistance.

        Matt

  2. The best Shinny applications I have come across in the Internet! Thank you very much for sharing them, I highly appreciate it!

    And Matt, you have implemented a plenty of useful features in your apps (helpPopup ect.), have you ever used a popup-closable-window? I am new to Shiny and have tried to find such a feature implementation, but with no results. Did I miss it while overlooking your app’s falicities?

    Best regards, Marta

    • Hi Marta,

      Thank you so much for your feedback! I am glad you like the apps. I do not know much javascript yet. I would like to know more but my time is generally taken up with 100% R.

      I borrowed the popup functionality from here: https://gist.github.com/jcheng5/5913297

      The Shiny Google Group is a great source for information. I think that is where I originally found the reference to the above code.

      Matt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: