amBarChart {rAmCharts4} | R Documentation |
HTML widget displaying a bar chart
Description
Create a HTML widget displaying a bar chart.
Usage
amBarChart(
data,
data2 = NULL,
category,
values,
valueNames = NULL,
showValues = TRUE,
hline = NULL,
yLimits = NULL,
expandY = 5,
valueFormatter = "#.",
chartTitle = NULL,
theme = NULL,
animated = TRUE,
draggable = FALSE,
tooltip = NULL,
columnStyle = NULL,
threeD = FALSE,
bullets = NULL,
alwaysShowBullets = FALSE,
backgroundColor = NULL,
cellWidth = NULL,
columnWidth = NULL,
xAxis = NULL,
yAxis = NULL,
scrollbarX = FALSE,
scrollbarY = FALSE,
legend = NULL,
caption = NULL,
image = NULL,
button = NULL,
cursor = FALSE,
width = NULL,
height = NULL,
export = FALSE,
chartId = NULL,
elementId = NULL
)
Arguments
data |
a dataframe |
data2 |
|
category |
name of the column of |
values |
name(s) of the column(s) of |
valueNames |
names of the values variables, to appear in the legend;
|
showValues |
logical, whether to display the values on the chart |
hline |
an optional horizontal line to add to the chart; it must be a
named list of the form |
yLimits |
range of the y-axis, a vector of two values specifying
the lower and the upper limits of the y-axis; |
expandY |
if |
valueFormatter |
a
number formatting string;
it is used to format the values displayed on the chart if
|
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
draggable |
|
tooltip |
settings of the tooltips; |
columnStyle |
settings of the columns (the bars); |
threeD |
logical, whether to render the columns in 3D |
bullets |
settings of the bullets; |
alwaysShowBullets |
logical, whether to always show the bullets;
if |
backgroundColor |
a color for the chart background; a color can be
given by the name of a R color, the name of a CSS color, e.g.
|
cellWidth |
cell width in percent; for a simple bar chart, this is the
width of the columns; for a grouped bar chart, this is the width of the
clusters of columns; |
columnWidth |
column width, a percentage of the cell width; set to 100
for a simple bar chart and use |
xAxis |
settings of the category axis given as a list, or just a string
for the axis title; the list of settings has three possible fields:
a field |
yAxis |
settings of the value axis given as a list, or just a string
for the axis title; the list of settings has five possible fields:
a field |
scrollbarX |
logical, whether to add a scrollbar for the category axis |
scrollbarY |
logical, whether to add a scrollbar for the value axis |
legend |
either a logical value, whether to display the legend, or
a list of settings for the legend created with |
caption |
|
image |
option to include an image at a corner of the chart;
|
button |
|
cursor |
option to add a cursor on the chart; |
width |
the width of the chart, e.g. |
height |
the height of the chart, e.g. |
export |
logical, whether to enable the export menu |
chartId |
a HTML id for the chart |
elementId |
a HTML id for the container of the chart; ignored if the chart is displayed in Shiny, in which case the id is given by the Shiny id |
Examples
# a simple bar chart ####
dat <- data.frame(
country = c("USA", "China", "Japan", "Germany", "UK", "France"),
visits = c(3025, 1882, 1809, 1322, 1122, 1114)
)
amBarChart(
data = dat, data2 = dat,
width = "600px",
category = "country", values = "visits",
draggable = TRUE,
tooltip =
"[bold font-style:italic #ffff00]{valueY.value.formatNumber('#,###.')}[/]",
chartTitle =
amText(text = "Visits per country", fontSize = 22, color = "orangered"),
xAxis = list(title = amText(text = "Country", color = "maroon")),
yAxis = list(
title = amText(text = "Visits", color = "maroon"),
gridLines = amLine(color = "orange", width = 1, opacity = 0.4)
),
yLimits = c(0, 4000),
valueFormatter = "#,###.",
caption = amText(text = "Year 2018", color = "red"),
theme = "material")
# bar chart with individual images in the bullets ####
dat <- data.frame(
language = c("Python", "Julia", "Java"),
users = c(10000, 2000, 5000),
href = c(
tinyIcon("python", "transparent"),
tinyIcon("julia", "transparent"),
tinyIcon("java", "transparent")
)
)
amBarChart(
data = dat,
width = "700px",
category = "language",
values = "users",
valueNames = list(users = "#users"),
showValues = FALSE,
tooltip = amTooltip(
text = "{name}: [bold]valueY[/]",
textColor = "white",
backgroundColor = "#101010",
borderColor = "silver"
),
draggable = FALSE,
backgroundColor = "seashell",
bullets = amCircle(
radius = 30,
color = "white",
strokeWidth = 4,
image = amImage(
href = "inData:href",
width = 50, height = 50
)
),
alwaysShowBullets = TRUE,
xAxis = list(title = amText(text = "Programming language")),
yAxis = list(
title = amText(text = "# users"),
gridLines = amLine(color = "orange", width = 1, opacity = 0.4)
),
yLimits = c(0, 12000),
valueFormatter = "#.",
theme = "material")
# a grouped bar chart ####
set.seed(666)
dat <- data.frame(
country = c("USA", "China", "Japan", "Germany", "UK", "France"),
visits = c(3025, 1882, 1809, 1322, 1122, 1114),
income = rpois(6, 25),
expenses = rpois(6, 20)
)
amBarChart(
data = dat,
width = "700px",
category = "country",
values = c("income", "expenses"),
valueNames = list(income = "Income", expenses = "Expenses"),
tooltip = amTooltip(
textColor = "white",
backgroundColor = "#101010",
borderColor = "silver"
),
draggable = list(income = TRUE, expenses = FALSE),
backgroundColor = "#30303d",
columnStyle = list(
income = amColumn(
color = "darkmagenta",
strokeColor = "#cccccc",
strokeWidth = 2
),
expenses = amColumn(
color = "darkred",
strokeColor = "#cccccc",
strokeWidth = 2
)
),
chartTitle = amText(text = "Income and expenses per country"),
xAxis = list(title = amText(text = "Country")),
yAxis = list(
title = amText(text = "Income and expenses"),
gridLines = amLine(color = "whitesmoke", width = 1, opacity = 0.4),
breaks = amAxisBreaks(values = seq(0, 45, by = 5))
),
yLimits = c(0, 45),
valueFormatter = "#.#",
caption = amText(text = "Year 2018"),
theme = "dark")