The gauge_* family of functions is similar to scale_* though there are some stark differences in places.

See motif vignette for examples of built-in color palettes.

Options

You can gauge aspects specific aspects, just like in ggplot2.

library(g2r)

g2(cars, asp(speed, dist, color = dist)) %>% 
  fig_point(asp(shape = "circle")) %>% 
  gauge_color(c("#FDE725", "#21908C", "#440154"))
g2(iris, asp(Sepal.Length, Sepal.Width, color = Species)) %>% 
  fig_point(asp(shape = Species), stroke = 0) %>% 
  gauge_shape(c("triangle", "circle", "square"))

Callback

You can also pass a JavaScript function to the gauge. The function must be wrapped in htmlwidgets::JS, the function must accept as argument the aspect variable used.

callback <- htmlwidgets::JS(
  "function(dist){
    if(dist > 50)
      return 'green';
    
    return 'red';
  }"
)

g2(cars, asp(speed, dist, color = dist)) %>% 
  fig_point(asp(shape = "circle")) %>% 
  gauge_color(callback) %>% 
  legend_color(FALSE)

Hide

To use a variable as gauge (e.g.: size, or color) and hide the legend pass a boolean to the appropriate legend_* function.

g2(cars, asp(speed, dist, size = dist)) %>% 
  fig_point() %>% 
  legend_size(FALSE)

Axis

Defaults:

By default g2r defines two options for the axis used in the chart.

One can also gauge the x and y axis.

g2(cars, asp(speed, dist)) %>% 
  fig_point() %>%
  fig_smooth(method = "polynomial") %>%  
  gauge_y_log()