# Gauge Chart in R

### How to replicate a google gauge chart in R?

Google charts has several options to produce nice graphics. Most of them have their equivalent function in R and can be quickly replicated, but some of them require a bit of programming.

For instance, take the google gauge charts which I really like:

A gauge is a very common chart used in information dashboards; you can use a gauge when you want to show a single value within a given scale. These charts typically show a key indicator within a range of values, employing a semaphoric color code (eg green, yellow, red). Although some people say gauges provide very little information for the amount of space they consume, we’re not going to discuss whether gauges are good or bad, or what type of colors we should use. We’re just going to see how we can create gauges in R.

### Preliminaries

Look at the following gauge from google charts:

We can distinguish the following elements:

• circles  (black and grey circles in the circumference)
• bands (yellow and red stripes)
• major ticks
• minor ticks
• minimum and maximum values (0, 100)
• value (eg 90)
• label (Memory)
• blue point in the middle
• needle

The idea is to break down the chart into its different components so we can have a better idea of how to create a gauge chart in R.

### Handy Functions

We will need three auxiliary functions to produce the circles, the stripe-bands, and the tick marks around the gauge. Keep in mind that we will be working going back and forth between radians and degrees to get the x-y coordinates of the elements we’re going to plot.

### Preparing elements

After defining the handy functions, we need to create the components that will be plotted: the black border, the gray circles, the yellow stripe, the red stripe, the major tick marks, the minor tick marks, the coordinates of the minimum and maximum values, the value indicator, the needle, and the label. Here’s how we can define all these elements:

### Putting everything together

Once we have all the ingredients, the last step is to put them all together in a plot like so:

Published in categories how-to  Tagged with chart  gauge  google charts  plot