bb_linechart {billboarder}R Documentation

Helper for creating a line chart

Description

Helper for creating a line chart

Usage

bb_linechart(
  bb,
  data,
  mapping = NULL,
  type = "line",
  show_point = FALSE,
  dasharray = NULL,
  width = NULL,
  ...
)

Arguments

bb

A billboard htmlwidget object.

data

A data.frame or a vector.

mapping

Mapping of variables on the chart, see bbaes.

type

Type of chart : "line", "spline", "step", "area", "area-spline", "area-step", "area-line-range", "area-spline-range".

show_point

Whether to show each point in line.

dasharray

Pattern of dashes and gaps used to paint the outline of the line, see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray for specifications.

width

Width of the stroke to be applied to the line, see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width for specifications.

...

Not used.

Value

A billboard htmlwidget object.

Note

Types area-line-range and area-spline-range don't work in RStudio viewer, open chart in a browser. This function can be used with billboarderProxy in shiny application.

Examples


## Different types
x <- round(rnorm(20), 2)

billboarder() %>% 
  bb_linechart(data = x)

billboarder() %>% 
  bb_linechart(data = x, type = "spline")

billboarder() %>% 
  bb_linechart(data = x, type = "area")

billboarder() %>% 
  bb_linechart(data = x, type = "area-spline")
  
  
## Timeserie with date (Date)
data("economics", package = "ggplot2")

billboarder() %>%
  bb_linechart(data = economics[, c("date", "psavert")]) %>% 
  bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) %>%
  bb_y_axis(tick = list(format = suffix("%")), 
            label = list(text = "Personal savings rate")) %>% 
  bb_legend(show = FALSE) %>% 
  bb_x_grid(show = TRUE) %>% 
  bb_y_grid(show = TRUE) %>% 
  bb_subchart(show = TRUE)
  
  
# With multiple lines :

data("economics_long", package = "ggplot2")

billboarder() %>%
  bb_linechart(economics_long, bbaes(date, value, variable)) %>% 
  bb_data(hide = "pop") %>% 
  bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE))
  
  

## Timeserie with datetime (POSIXct)
data("cdc_prod_filiere")

billboarder() %>% 
  bb_linechart(data = cdc_prod_filiere[, c("date_heure", "prod_eolien")])

# or with mapping :
billboarder() %>% 
  bb_linechart(cdc_prod_filiere, bbaes(date_heure, prod_bioenergies))
  
  
 
### Other type for x-axis 
 
## character/factor on x-axis
AirPassengers1960 <- data.frame(
  month = month.name, 
  AirPassengers = tail(AirPassengers, 12)
)
# you have to specify that x-axis is of type 'category'
# and that column 'month' must be used for x-axis values
billboarder() %>% 
  bb_linechart(data = AirPassengers1960, x = "month") %>% 
  bb_x_axis(type = "category")


## numeric on x-axis
lynx.df <- data.frame(
  year = time(lynx),
  lynx = lynx
)
# just specify which variable must be use n the x-axis
billboarder() %>% 
  bb_linechart(data = lynx.df, x = "year")
  
  
### Area range charts

# Generate data
dat <- data.frame(
  date = seq.Date(Sys.Date(), length.out = 20, by = "day"),
  y1 = round(rnorm(20, 100, 15)),
  y2 = round(rnorm(20, 100, 15))
)
dat$ymin1 <- dat$y1 - 5
dat$ymax1 <- dat$y1 + 5

dat$ymin2 <- dat$y2 - sample(3:15, 20, TRUE)
dat$ymax2 <- dat$y2 + sample(3:15, 20, TRUE)


# Make chart : use ymin & ymax aes for range
billboarder(data = dat) %>% 
  bb_linechart(
    mapping = bbaes(x = date, y = y1, ymin = ymin1, ymax = ymax1),
    type = "area-line-range"
  ) %>% 
  bb_linechart(
    mapping = bbaes(x = date, y = y2, ymin = ymin2, ymax = ymax2), 
    type = "area-spline-range"
  ) %>% 
  bb_y_axis(min = 50)
  

[Package billboarder version 0.4.1 Index]