Skip to main content
AI in Production 2026 is now open for talk proposals.
Share insights that help teams build, scale, and maintain stronger AI systems.
items
Menu
  • About
    • Overview 
    • Join Us  
    • Community 
    • Contact 
  • Training
    • Overview 
    • Course Catalogue 
    • Public Courses 
  • Posit
    • Overview 
    • License Resale 
    • Managed Services 
    • Health Check 
  • Data Science
    • Overview 
    • Visualisation & Dashboards 
    • Open-source Data Science 
    • Data Science as a Service 
    • Gallery 
  • Engineering
    • Overview 
    • Cloud Solutions 
    • Enterprise Applications 
  • Our Work
    • Blog 
    • Case Studies 
    • R Package Validation 
    • diffify  

Sparkline Package for Inline Visualisations

Author: Osheen MacOscar

Published: February 13, 2025

tags: r, sparkline, widget, shiny

Introduction

Sparkline

This was the introductory part of the blog series, the second part will be on embedding sparklines in html tables. The CRAN {sparkline} package allows you to make small inline html charts using jQuery in R.

Charts Available With {sparkline}

You can make the following charts with the package:

  • Line
  • Bar
  • Tristate
  • Discrete
  • Bullet
  • Pie
  • Box Plot

The omnipotent.net website has a great feature for viewing the different types of chart. I will show a few examples here, along with the code for producing them.

Note the documentation for all of the different charts is great and can be found here.

All of the plots from this package use the sparkline function, and we pass the type of chart we want as the type argument (default is line). The function will take a vector or list for the values argument, depending on the type of chart we are creating this can be either data to plot or specifications for the plot.

Note: I am using spk_add_deps so I can display them in this blog.

Data comes in all shapes and sizes. It can often be difficult to know where to start. Whatever your problem, Jumping Rivers can help.

Line

library(sparkline)

data = list(1, 2, 3, 5, 2, 3, 4, 6, 9, 2, 4, 6)

line1 = sparkline(values = data, type = "line") |>
  spk_add_deps()

We can remove the fill and the spots using the following arguments.

line2 = sparkline(values = data, type = "line", spotRadius = "", fillColor = "")

Bar

bar1 = sparkline(values = data, type = "bar")

We can change the bar colors, spacing and width.

bar2 = sparkline(values = data, type = "bar", barColor = "red", barSpacing = "10", barWidth = 8)

Box Plots

For box plots, the data passed to the values argument will be used to calculate the chart. If you want to pass in pre-computed values like median, max or min for example, you can do this using the raw = TRUE and pass them in as the values argument.

box = sparkline(values = data, type = "box")

Bullet Graph

This is one of the examples where the values passed correspond to specifications for the plot and should be ordered as: target, performance, range1, range2, range3.

bullet1 = sparkline(values = c(7, 5, 10, 6, 3), type = "bullet")
bullet2 = sparkline(values = c(7, 5, 10, 6, 3), type = "bullet", rangeColors = c("lightgrey", "grey", "slategrey"))

See you in the next blog post about embedding sparklines in html tables.


Jumping Rivers Logo

Recent Posts

  • Start 2026 Ahead of the Curve: Boost Your Career with Jumping Rivers Training 
  • Should I Use Figma Design for Dashboard Prototyping? 
  • Announcing AI in Production 2026: A New Conference for AI and ML Practitioners 
  • Elevate Your Skills and Boost Your Career – Free Jumping Rivers Webinar on 20th November! 
  • Get Involved in the Data Science Community at our Free Meetups 
  • Polars and Pandas - Working with the Data-Frame 
  • Highlights from Shiny in Production (2025) 
  • Elevate Your Data Skills with Jumping Rivers Training 
  • Creating a Python Package with Poetry for Beginners Part2 
  • What's new for Python in 2025? 

Top Tags

  • R (236) 
  • Rbloggers (182) 
  • Pybloggers (89) 
  • Python (89) 
  • Shiny (63) 
  • Events (26) 
  • Training (23) 
  • Machine Learning (22) 
  • Conferences (20) 
  • Tidyverse (17) 
  • Statistics (14) 
  • Packages (13) 

Authors

  • Amieroh Abrahams 
  • Shane Halloran 
  • Russ Hyde 
  • Myles Mitchell 
  • Tim Brock 
  • Theo Roe 
  • Colin Gillespie 
  • Aida Gjoka 
  • Gigi Kenneth 
  • Osheen MacOscar 
  • Sebastian Mellor 
  • Keith Newman 
  • Pedro Silva 

Keep Updated

Like data science? R? Python? Stan? Then you’ll love the Jumping Rivers newsletter. The perks of being part of the Jumping Rivers family are:

  • Be the first to know about our latest courses and conferences.
  • Get discounts on the latest courses.
  • Read news on the latest techniques with the Jumping Rivers blog.

We keep your data secure and will never share your details. By subscribing, you agree to our privacy policy.

Follow Us

  • GitHub
  • Bluesky
  • LinkedIn
  • YouTube
  • Eventbrite

Find Us

The Catalyst Newcastle Helix Newcastle, NE4 5TG
Get directions

Contact Us

  • hello@jumpingrivers.com
  • + 44(0) 191 432 4340

Newsletter

Sign up

Events

  • North East Data Scientists Meetup
  • Leeds Data Science Meetup
  • Shiny in Production
British Assessment Bureau, UKAS Certified logo for ISO 9001 - Quality management British Assessment Bureau, UKAS Certified logo for ISO 27001 - Information security management Cyber Essentials Certified Plus badge
  • Privacy Notice
  • |
  • Booking Terms

©2016 - present. Jumping Rivers Ltd