lc_bars: Create a barplot

Description Usage Arguments Available properties Examples

View source: R/lc.R

Description

lc_bars creates a new barplot and adds it to the app and all currently opened pages as a new chart or a new layer of an existing chart.

Usage

1
2
3
4
5
6
7
8
9
lc_bars(
  data = list(),
  place = NULL,
  ...,
  chartId = NULL,
  layerId = NULL,
  with = NULL,
  addLayer = FALSE
)

Arguments

data

Name-value pairs of properties passed through the dat function. These properties will be re-evaluated on each updateCharts call.

place

An ID of the container, where to place new chart. It will be ignored if the chart already exists. If not defined, the chart will be appended to the web page's body.

...

Name-value pairs of properties that will be evaluated only once and then will remain constant. These properties can still be changed later using the setProperties function.

chartId

An ID for the chart. All charts must have unique IDs. If a chart with the same ID already exists, it will be replaced unless addLayer = TRUE. If ID is not defined, it will be the same as the value of the place argument. And if both are not defined, the ID will be set to ChartN, where N - 1 is the number of existing charts.

layerId

An ID for the new layer. All layers within one chart must have different IDs. If a layer with the same ID already exists, it will be replaced. If not defined, it will be set to LayerN, where N - 1 is the current number of layers in this chart.

with

A dataset or a list from which other properties should be taken. If the dataset doesn't have a column with the requested name, the variable will be searched for outside of the dataset. Must be a data.frame or a list.

addLayer

If there is already a chart with the same ID, this argument defines whether to replace it or to add a new layer to it. This argument is ignored if both place and chartId are NULL or if there is no chart with the given ID.

Available properties

You can read more about different properties here.

Style settings

Axes settings

Interactivity settings

Legend settings

Global chart settings

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
data("esoph")

lc_bars(dat(value = tapply(esoph$ncases, esoph$agegp, sum), 
            title = "Number of cases per age group",
            axisTitleX = "Age group", 
            axisTitleY = "Number of esophageal cases",
            axisTitlePosX = "down"))

lc_bars(dat(value = c(tapply(esoph$ncases, esoph$agegp, sum), 
                      tapply(esoph$ncontrols, esoph$agegp, sum)),
            stackIds = c(rep("case", 6), rep("control", 6))))

#It is easy to put data in a convenient form for barplots using tidyverse
library(magrittr)
library(dplyr)
library(tidyr)
library(stringr)

esoph %>%
  gather(type, cases, (ncases:ncontrols)) %>%
  mutate(type = str_sub(type, 2, -2)) %>%
  group_by(agegp, alcgp, type) %>%
  summarise(ncases = sum(cases)) -> newData

lc_bars(dat(value = newData$ncases,
            stackIds = newData$type,
            barIds = newData$alcgp,
            groupIds = newData$agegp))

rlc documentation built on Jan. 5, 2022, 1:11 a.m.

Related to lc_bars in rlc...