First, you should load recharts:

library(recharts)

1 Introduction

The default position of dataRange is 8 o’clock.

The recommended approach to use setDataRange is chart %>% setDataRange(...).

2 Function Call

All the function names have two forms: small camel and lowercase_underscore (endorsed by Hadley Wickham). To be lazy, we also provide short forms as well (e.g., dr for dataRange).

setDataRange(chart, show = TRUE, pos = 8, valueRange = NULL,
  splitNumber = 5, itemGap = 5, labels = NULL, calculable = FALSE,
  borderColor = "#ccc", borderWidth = 0, selectedMode = list(TRUE,
  "single", "multiple"), color = c("#1e90ff", "#f0ffff"), splitList = NULL,
  initialRange = NULL, ...)

set_datarange(chart, show = TRUE, pos = 8, valueRange = NULL,
  splitNumber = 5, itemGap = 5, labels = NULL, calculable = FALSE,
  borderColor = "#ccc", borderWidth = 0, selectedMode = list(TRUE,
  "single", "multiple"), color = c("#1e90ff", "#f0ffff"), splitList = NULL,
  initialRange = NULL, ...)

set_dr(chart, show = TRUE, pos = 8, valueRange = NULL, splitNumber = 5,
  itemGap = 5, labels = NULL, calculable = FALSE, borderColor = "#ccc",
  borderWidth = 0, selectedMode = list(TRUE, "single", "multiple"),
  color = c("#1e90ff", "#f0ffff"), splitList = NULL, initialRange = NULL,
  ...)

setDR(chart, show = TRUE, pos = 8, valueRange = NULL, splitNumber = 5,
  itemGap = 5, labels = NULL, calculable = FALSE, borderColor = "#ccc",
  borderWidth = 0, selectedMode = list(TRUE, "single", "multiple"),
  color = c("#1e90ff", "#f0ffff"), splitList = NULL, initialRange = NULL,
  ...)
Arg Requirement

chart

Echarts object generated by echartR or echart.

show

logical. Show the dataRange control if TRUE. If you want to remove dataRange from the echarts object, set it NULL.

pos

the clock-position of dataRange, default 8. Refer to vecPos. Or you can define the position vector c(x, y, orient) yourself.

valueRange

The range of the dataRange bar in form of c(min, max). If NULL, echarts default will be used.

splitNumber

How many discrete sections will the dataRange bar be divided into. Default 5. Set it to 0 to set the bar continuous and calculable will be accordingly set TRUE.

itemGap

The gap between itmes in pixels. Default 10px.

labels

The labels to the ends the dataRange bar in form c('high end', 'low end'). Default NULL, the min, max values will be used.

calculable

Logical. If echart calculable feature is open. Default FALSE. If set calculable TRUE, splitNumber will be set 0.

borderColor

The border color of the dataRange bar. Default ‘#333’.

borderWidth

The border width of the dataRange bar. Default 0px (not shown).

selectedMode

The mode of the dataRange bar, default TRUE. You can also set it ‘single’ or ‘multiple’.

color

The hex vector of colors used for dataRange bar. Default c(“#1e90ff”, “#f0ffff”).

splitList

A list for user-defined value split in the form of list(list(start=m, end=n, label=x, color=hex), ...). If a valid splitList is set, splitNumber will be disabled.

initialRange

Initial selected value range in the form of list(start=m, end=n), of which m and n all refer to percentage.

Elipsis.

3 Showcase

In a scatter chart, only weight is mapped to dataRange. So let’s prepare a bubble chart.

g <- echartr(iris, Sepal.Width, Petal.Width, Species, Petal.Length,
             type='bubble') %>% setSymbols('circle')
g

Initially dataRange is not shown. Let’s turn if on. Then you will find dataRange color palette overides the orignial palette of the chart.

g %>% setDataRange(show=TRUE)

Relocate the dataRange.

g %>% setDataRange(pos=9)

Modify the valueRange.

g %>% setDataRange(valueRange=c(0,10))

Render a continuous dataRange bar.

g %>% setDataRange(splitNumber=0)

Customize the format.

g %>% setDataRange(borderColor='gray', borderWidth=2,bgColor='yellow', 
                   itemGap=20)

Customize the color of the controls.

g %>% setDataRange(color=getColFromPal('rainbow'))

By default, the splitNumber is 5 and the scale is evenly splited. You can assign user-defined splitList to overide the defaults.

splitList <-list(
    list(start=5.1, end=7, label='5.1 - 7.0', color='red'),
    list(start=4.35, end=5.1, label='4.35 - 5.1', color='yellow'),
    list(start=1.6, end=4.35, label='1.6 - 4.35', color='lime'),
    list(start=0, end=1.6, label='0.0 - 1.6', color='cyan')
    )
g %>% setDataRange(splitList=splitList)

Set the initialRange when the dataRange is continuous.

g %>% setDataRange(initialRange=list(start=20, end=60), splitNumber=0)