First post on our blog! We welcome all data enthusiasts!
Today we are going to show you how to use a tinny but useful library called sparkline. Sparkline itself is a small widget that uses jQuery under the hood1.
Lets get straight to the point and look at some examples.
Install: As this package is not available at CRAN we need to install it with devtools3:
We need some data to play with. In this case we’re going to use weather forecasts for New York:
Types of charts
Sparkline has several flavors.
- Bar chart where we can adjust bar colors
- Bullet graph:
- And of course pie chart:
You can also use two types tristate and discrete, however I’ve never used those two until this time (check out documentation if you curious!).
I’ve shown how you can pass arguments to plots in the examples. A Precise explaination of all options and configurations is available in jQuery plugin documentation.
It gets even better if we embed sparkline within tables with data. Familiar with formattable? You will be!
I had to use a small trick here. Who knows what I did?
Formattable lets you do that and more when it comes to presenting your data in readable form. It has its own htmlwidget as well.
For those of you who think that charts in the browser are mainstream I recommend working with command line. spark Not the best choice when it comes to the name of the library. is a simillar package to sparkline, but it renders charts straight in the command line!
jQuery is an old but still very popular library that allows to quickly implement various actions on websites (like animations, DOM manipulations, async calls). jQuery is replaced more and more often with some modern tools, but for some basic projects this is still good way to go. ↩