Title: | Interface to the JavaScript Library 'amCharts 4' |
---|---|
Description: | Creates JavaScript charts. The charts can be included in 'Shiny' apps and R markdown documents, or viewed from the R console and 'RStudio' viewer. Based on the JavaScript library 'amCharts 4' and the R packages 'htmlwidgets' and 'reactR'. Currently available types of chart are: vertical and horizontal bar chart, radial bar chart, stacked bar chart, vertical and horizontal Dumbbell chart, line chart, scatter chart, range area chart, gauge chart, boxplot chart, pie chart, and 100% stacked bar chart. |
Authors: | Stéphane Laurent [aut, cre], Antanas Marcelionis [ctb, cph] ('amCharts' library (https://www.amcharts.com/)), Terence Eden [ctb, cph] ('SuperTinyIcons' library (https://github.com/edent/SuperTinyIcons/)), Tom Alexander [ctb, cph] ('regression-js' library (https://github.com/Tom-Alexander/regression-js)) |
Maintainer: | Stéphane Laurent <[email protected]> |
License: | GPL-3 |
Version: | 1.6.1 |
Built: | 2024-10-26 03:09:46 UTC |
Source: | https://github.com/stla/ramcharts4 |
Create an object defining the breaks on an axis.
amAxisBreaks( values = NULL, labels = NULL, interval = NULL, timeInterval = NULL )
amAxisBreaks( values = NULL, labels = NULL, interval = NULL, timeInterval = NULL )
values |
positions of the breaks, a vector of values; for a date axis, this must be a vector of dates |
labels |
if |
interval |
for equally spaced breaks, the number of pixels between two
consecutive breaks; ignored if |
timeInterval |
for equally spaced breaks on a date axis, this option
defines the interval between two consecutive breaks; it must be a string
like |
Create a list of settings for the labels of an axis.
amAxisLabels( color = NULL, fontSize = 18, fontWeight = "normal", fontFamily = NULL, rotation = 0, formatter = NULL ) amAxisLabelsCircular( color = NULL, fontSize = 14, fontWeight = "normal", fontFamily = NULL, radius = NULL, relativeRotation = NULL )
amAxisLabels( color = NULL, fontSize = 18, fontWeight = "normal", fontFamily = NULL, rotation = 0, formatter = NULL ) amAxisLabelsCircular( color = NULL, fontSize = 14, fontWeight = "normal", fontFamily = NULL, radius = NULL, relativeRotation = NULL )
color |
color of the labels |
fontSize |
size of the labels |
fontWeight |
font weight of the labels, it can be |
fontFamily |
font family of the labels |
rotation |
rotation angle |
formatter |
this option defines the format of the axis labels;
this should be a
number formatting string
for a numeric axis, and a list created with
|
radius |
radius in percentage |
relativeRotation |
relative rotation angle |
A list of settings for the labels of an axis.
A color can be given by the name of a R color, the name of a CSS
color, e.g. "silver"
or "fuchsia"
, an HEX code like
"#ff009a"
, a RGB code like "rgb(255,100,39)"
, or a HSL code
like "hsl(360,11,255)"
.
Create a HTML widget displaying a bar chart.
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 )
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 )
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 |
# 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")
# 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")
Create a HTML widget displaying a boxplot chart.
amBoxplotChart( data, category, value, color = NULL, hline = NULL, yLimits = NULL, expandY = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, tooltip = TRUE, bullets = NULL, backgroundColor = NULL, xAxis = NULL, yAxis = NULL, scrollbarX = FALSE, scrollbarY = FALSE, caption = NULL, image = NULL, cursor = FALSE, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
amBoxplotChart( data, category, value, color = NULL, hline = NULL, yLimits = NULL, expandY = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, tooltip = TRUE, bullets = NULL, backgroundColor = NULL, xAxis = NULL, yAxis = NULL, scrollbarX = FALSE, scrollbarY = FALSE, caption = NULL, image = NULL, cursor = FALSE, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
data |
a dataframe |
category |
name of the column of |
value |
name of the column of |
color |
the color of the boxplots; it can be given by the name of a R
color, the name of a CSS color, e.g. |
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 in the cursor tooltips,
the labels of the y-axis unless you specify
your own formatter in the |
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
tooltip |
|
bullets |
settings of the bullets representing the outliers;
|
backgroundColor |
a color for the chart background; it can be
given by the name of a R color, the name of a CSS color, e.g.
|
xAxis |
settings of the category axis given as a list, or just a string
for the axis title; the list of settings has four 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 |
caption |
|
image |
option to include an image at a corner of the chart;
|
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 |
library(rAmCharts4) set.seed(666) dat <- data.frame( group = gl(4, 50, labels = c("A", "B", "C", "D")), y = rt(200, df = 3) ) amBoxplotChart( dat, category = "group", value = "y", color = "maroon", valueFormatter = "#.#", theme = "moonrisekingdom" )
library(rAmCharts4) set.seed(666) dat <- data.frame( group = gl(4, 50, labels = c("A", "B", "C", "D")), y = rt(200, df = 3) ) amBoxplotChart( dat, category = "group", value = "y", color = "maroon", valueFormatter = "#.#", theme = "moonrisekingdom" )
Create a list of settings for a button.
amButton(label, color = NULL, position = 0.9, marginRight = 10)
amButton(label, color = NULL, position = 0.9, marginRight = 10)
label |
label of the button, a character string or a list created with
|
color |
button color |
position |
the vertical position of the button: |
marginRight |
right margin in pixels |
A list of settings for a button.
Create a list of settings for the columns of a bar chart.
amColumn( color = NULL, opacity = NULL, strokeColor = NULL, strokeWidth = 4, cornerRadius = 8 )
amColumn( color = NULL, opacity = NULL, strokeColor = NULL, strokeWidth = 4, cornerRadius = 8 )
color |
color of the columns; this can be a color adapter |
opacity |
opacity of the columns, a number between 0 and 1 |
strokeColor |
color of the border of the columns; this can be a color adapter |
strokeWidth |
width of the border of the columns |
cornerRadius |
radius of the corners of the columns |
A list of settings for usage in amBarChart
or amHorizontalBarChart
A color can be given by the name of a R color, the name of a CSS
color, e.g. "transparent"
or "fuchsia"
, an HEX code like
"#ff009a"
, a RGB code like "rgb(255,100,39)"
, or a HSL code
like "hsl(360,11,255)"
.
Create a list of settings for formatting the labels of a
date axis, to be passed on to the formatter
argument of
amAxisLabels
.
amDateAxisFormatter( day = c("dd", "MMM dd"), week = c("dd", "MMM dd"), month = c("MMM", "MMM yyyy") )
amDateAxisFormatter( day = c("dd", "MMM dd"), week = c("dd", "MMM dd"), month = c("MMM", "MMM yyyy") )
day , week , month
|
vectors of length two, the first component is a formatting string for the dates within a period, and the second one is a formatting string for the dates at a period change; see Formatting date and time |
A list of settings for formatting the labels of a date axis.
Create a HTML widget displaying a Dumbbell chart.
amDumbbellChart( data, data2 = NULL, category, values, seriesNames = NULL, hline = NULL, yLimits = NULL, expandY = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, segmentsStyle = NULL, bullets = NULL, backgroundColor = 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 )
amDumbbellChart( data, data2 = NULL, category, values, seriesNames = NULL, hline = NULL, yLimits = NULL, expandY = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, segmentsStyle = NULL, bullets = NULL, backgroundColor = 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 )
data |
a dataframe |
data2 |
|
category |
name of the column of |
values |
a character matrix with two columns; each row corresponds to
a series and provides the names of two columns of |
seriesNames |
a character vector providing the names of the series
to appear in the legend; its length must equal the number of rows of the
|
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 in the cursor tooltips,
the labels of the y-axis unless you specify
your own formatter in the |
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
draggable |
|
tooltip |
settings of the tooltips; |
segmentsStyle |
settings of the segments; |
bullets |
settings of the bullets; |
backgroundColor |
a color for the chart background; it can be
given by the name of a R color, the name of a CSS color, e.g.
|
xAxis |
settings of the category axis given as a list, or just a string
for the axis title; the list of settings has four 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 |
dat <- data.frame( x = c("T0", "T1", "T2"), y1 = c(7, 15, 10), y2 = c(20, 25, 23), z1 = c(5, 10, 5), z2 = c(25, 20, 15) ) amDumbbellChart( width = "500px", data = dat, draggable = TRUE, category = "x", values = rbind(c("y1","y2"), c("z1","z2")), seriesNames = c("Control", "Treatment"), yLimits = c(0, 30), segmentsStyle = list( "Control" = amSegment(width = 2), "Treatment" = amSegment(width = 2) ), bullets = list( y1 = amTriangle(strokeWidth = 0), y2 = amTriangle(rotation = 180, strokeWidth = 0), z1 = amTriangle(strokeWidth = 0), z2 = amTriangle(rotation = 180, strokeWidth = 0) ), tooltip = amTooltip("upper: {openValueY}\nlower: {valueY}", scale = 0.75), xAxis = list( title = amText( "timepoint", fontSize = 17, fontWeight = "bold", fontFamily = "Helvetica" ) ), yAxis = list( title = amText( "response", fontSize = 17, fontWeight = "bold", fontFamily = "Helvetica" ), gridLines = amLine("silver", width = 1, opacity = 0.4) ), legend = amLegend(position = "right", itemsWidth = 15, itemsHeight = 15), backgroundColor = "lightyellow", theme = "dataviz" )
dat <- data.frame( x = c("T0", "T1", "T2"), y1 = c(7, 15, 10), y2 = c(20, 25, 23), z1 = c(5, 10, 5), z2 = c(25, 20, 15) ) amDumbbellChart( width = "500px", data = dat, draggable = TRUE, category = "x", values = rbind(c("y1","y2"), c("z1","z2")), seriesNames = c("Control", "Treatment"), yLimits = c(0, 30), segmentsStyle = list( "Control" = amSegment(width = 2), "Treatment" = amSegment(width = 2) ), bullets = list( y1 = amTriangle(strokeWidth = 0), y2 = amTriangle(rotation = 180, strokeWidth = 0), z1 = amTriangle(strokeWidth = 0), z2 = amTriangle(rotation = 180, strokeWidth = 0) ), tooltip = amTooltip("upper: {openValueY}\nlower: {valueY}", scale = 0.75), xAxis = list( title = amText( "timepoint", fontSize = 17, fontWeight = "bold", fontFamily = "Helvetica" ) ), yAxis = list( title = amText( "response", fontSize = 17, fontWeight = "bold", fontFamily = "Helvetica" ), gridLines = amLine("silver", width = 1, opacity = 0.4) ), legend = amLegend(position = "right", itemsWidth = 15, itemsHeight = 15), backgroundColor = "lightyellow", theme = "dataviz" )
Create a list of settings for a font.
amFont(fontSize = NULL, fontWeight = "normal", fontFamily = NULL)
amFont(fontSize = NULL, fontWeight = "normal", fontFamily = NULL)
fontSize |
font size, must be given as a character string like
|
fontWeight |
font weight, it can be |
fontFamily |
font family |
A list of settings for a font.
There is no option for the font style.
Create a HTML widget displaying a gauge chart.
amGaugeChart( score, minScore, maxScore, scorePrecision = 0, gradingData, innerRadius = 70, labelsRadius = (100 - innerRadius)/2, axisLabelsRadius = 19, chartFontSize = 11, labelsFont = amFont(fontSize = "2em", fontWeight = "bold"), axisLabelsFont = amFont(fontSize = "1.2em"), scoreFont = amFont(fontSize = "6em"), scoreLabelFont = amFont(fontSize = "2em"), hand = amHand(innerRadius = 45, width = 8, color = "slategray", strokeColor = "black"), gridLines = FALSE, chartTitle = NULL, theme = NULL, animated = TRUE, backgroundColor = NULL, caption = NULL, image = NULL, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
amGaugeChart( score, minScore, maxScore, scorePrecision = 0, gradingData, innerRadius = 70, labelsRadius = (100 - innerRadius)/2, axisLabelsRadius = 19, chartFontSize = 11, labelsFont = amFont(fontSize = "2em", fontWeight = "bold"), axisLabelsFont = amFont(fontSize = "1.2em"), scoreFont = amFont(fontSize = "6em"), scoreLabelFont = amFont(fontSize = "2em"), hand = amHand(innerRadius = 45, width = 8, color = "slategray", strokeColor = "black"), gridLines = FALSE, chartTitle = NULL, theme = NULL, animated = TRUE, backgroundColor = NULL, caption = NULL, image = NULL, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
score |
gauge value, a number between |
minScore |
minimal score |
maxScore |
maximal score |
scorePrecision |
an integer, the number of decimals of the score to be displayed |
gradingData |
data for the gauge, a dataframe with three required
columns: |
innerRadius |
inner radius of the gauge given as a percentage,
between |
labelsRadius |
radius for the labels given as a percentage; use the default value to get centered labels |
axisLabelsRadius |
radius for the axis labels given as a percentage |
chartFontSize |
reference font size, a numeric value, the font size in
pixels; this font size has an effect only if you use the relative CSS unit
|
labelsFont |
a list of settings for the font of the labels created with
|
axisLabelsFont |
a list of settings for the font of the axis labels
created with |
scoreFont |
a list of settings for the font of the score created with
|
scoreLabelFont |
a list of settings for the font of the score label
created with |
hand |
a list of settings for the hand of the gauge created with
|
gridLines |
a list of settings for the grid lines created with
|
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
backgroundColor |
a color for the chart background; it can be given by
the name of a R color, the name of a CSS
color, e.g. |
caption |
|
image |
option to include an image at a corner of 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 |
In Shiny, you can change the score of a gauge chart with the help of
updateAmGaugeChart
.
library(rAmCharts4) gradingData <- data.frame( label = c("Slow", "Moderate", "Fast"), color = c("blue", "green", "red"), lowScore = c(0, 100/3, 200/3), highScore = c(100/3, 200/3, 100) ) amGaugeChart( score = 40, minScore = 0, maxScore = 100, gradingData = gradingData )
library(rAmCharts4) gradingData <- data.frame( label = c("Slow", "Moderate", "Fast"), color = c("blue", "green", "red"), lowScore = c(0, 100/3, 200/3), highScore = c(100/3, 200/3, 100) ) amGaugeChart( score = 40, minScore = 0, maxScore = 100, gradingData = gradingData )
Create a list of settings for the hand of a gauge chart.
amHand(innerRadius, width, color, strokeColor)
amHand(innerRadius, width, color, strokeColor)
innerRadius |
inner radius of the hand, given as a percentage |
width |
width of the base of the hand in pixels, a positive number |
color |
color of the hand |
strokeColor |
stroke color of the hand |
A list of settings for the hand of a gauge chart.
Create a HTML widget displaying a horizontal bar chart.
amHorizontalBarChart( data, data2 = NULL, category, values, valueNames = NULL, showValues = TRUE, vline = NULL, xLimits = NULL, expandX = 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 )
amHorizontalBarChart( data, data2 = NULL, category, values, valueNames = NULL, showValues = TRUE, vline = NULL, xLimits = NULL, expandX = 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 )
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 |
vline |
an optional vertical line to add to the chart; it must be a
named list of the form |
xLimits |
range of the x-axis, a vector of two values specifying the
left and the right limits of the x-axis; |
expandX |
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; |
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 value axis given as a list, or just a string
for the axis title; the list of settings has five possible fields:
a field |
yAxis |
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 |
scrollbarX |
logical, whether to add a scrollbar for the value axis |
scrollbarY |
logical, whether to add a scrollbar for the category axis |
legend |
|
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 |
# a simple horizontal bar chart #### dat <- data.frame( country = c("USA", "China", "Japan", "Germany", "UK", "France"), visits = c(3025, 1882, 1809, 1322, 1122, 1114) ) amHorizontalBarChart( data = dat, data2 = dat, width = "600px", height = "550px", category = "country", values = "visits", draggable = TRUE, tooltip = "[font-style:italic #ffff00]{valueX}[/]", chartTitle = amText(text = "Visits per country", fontSize = 22, color = "orangered"), xAxis = list( title = amText(text = "Country", color = "maroon"), gridLines = amLine(opacity = 0.4, width = 1, dash = "3,1") ), yAxis = list(title = amText(text = "Visits", color = "maroon")), xLimits = c(0, 4000), valueFormatter = "#,###", caption = amText(text = "Year 2018", color = "red"), theme = "moonrisekingdom") # a grouped horizontal 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) ) amHorizontalBarChart( data = dat, width = "700px", category = "country", values = c("income", "expenses"), valueNames = list(income = "Income", expenses = "Expenses"), tooltip = amTooltip( text = "[bold]{name}:\n{valueX}[/]", 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"), yAxis = list(title = amText(text = "Country")), xAxis = list( title = amText(text = "Income and expenses"), gridLines = amLine(color = "whitesmoke", width = 1, opacity = 0.4) ), xLimits = c(0, 41), valueFormatter = "#.#", caption = amText(text = "Year 2018"), theme = "dark")
# a simple horizontal bar chart #### dat <- data.frame( country = c("USA", "China", "Japan", "Germany", "UK", "France"), visits = c(3025, 1882, 1809, 1322, 1122, 1114) ) amHorizontalBarChart( data = dat, data2 = dat, width = "600px", height = "550px", category = "country", values = "visits", draggable = TRUE, tooltip = "[font-style:italic #ffff00]{valueX}[/]", chartTitle = amText(text = "Visits per country", fontSize = 22, color = "orangered"), xAxis = list( title = amText(text = "Country", color = "maroon"), gridLines = amLine(opacity = 0.4, width = 1, dash = "3,1") ), yAxis = list(title = amText(text = "Visits", color = "maroon")), xLimits = c(0, 4000), valueFormatter = "#,###", caption = amText(text = "Year 2018", color = "red"), theme = "moonrisekingdom") # a grouped horizontal 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) ) amHorizontalBarChart( data = dat, width = "700px", category = "country", values = c("income", "expenses"), valueNames = list(income = "Income", expenses = "Expenses"), tooltip = amTooltip( text = "[bold]{name}:\n{valueX}[/]", 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"), yAxis = list(title = amText(text = "Country")), xAxis = list( title = amText(text = "Income and expenses"), gridLines = amLine(color = "whitesmoke", width = 1, opacity = 0.4) ), xLimits = c(0, 41), valueFormatter = "#.#", caption = amText(text = "Year 2018"), theme = "dark")
Create a HTML widget displaying a horizontal Dumbbell chart.
amHorizontalDumbbellChart( data, data2 = NULL, category, values, seriesNames = NULL, vline = NULL, xLimits = NULL, expandX = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, segmentsStyle = NULL, bullets = NULL, backgroundColor = 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 )
amHorizontalDumbbellChart( data, data2 = NULL, category, values, seriesNames = NULL, vline = NULL, xLimits = NULL, expandX = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, segmentsStyle = NULL, bullets = NULL, backgroundColor = 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 )
data |
a dataframe |
data2 |
|
category |
name of the column of |
values |
a character matrix with two columns; each row corresponds to
a series and provides the names of two columns of |
seriesNames |
a character vector providing the names of the series
to appear in the legend; its length must equal the number of rows of the
|
vline |
an optional vertical line to add to the chart; it must be a
named list of the form |
xLimits |
range of the x-axis, a vector of two values specifying
the left and right limits of the x-axis; |
expandX |
if |
valueFormatter |
a
number formatting string;
it is used to format the values displayed in the cursor tooltips,
the labels of the x-axis unless you specify
your own formatter in the |
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
draggable |
|
tooltip |
settings of the tooltips; |
segmentsStyle |
settings of the segments; |
bullets |
settings of the bullets; |
backgroundColor |
a color for the chart background; it can be
given by the name of a R color, the name of a CSS color, e.g.
|
xAxis |
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 |
yAxis |
settings of the category axis given as a list, or just a string
for the axis title; the list of settings has four possible fields:
a field |
scrollbarX |
logical, whether to add a scrollbar for the value axis |
scrollbarY |
logical, whether to add a scrollbar for the category 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 |
set.seed(666) lwr <- rpois(20, 5) dat <- data.frame( comparison = paste0("Ctrl vs. ", LETTERS[1:20]), lwr = lwr, upr = lwr + rpois(20, 10) ) amHorizontalDumbbellChart( width = "500px", height = "450px", data = dat, draggable = TRUE, category = "comparison", values = rbind(c("lwr", "upr")), xLimits = c(0, 30), segmentsStyle = amSegment(width = 1, color = "darkred"), bullets = amCircle(strokeWidth = 0, color = "darkred"), tooltip = amTooltip("left: {valueX}\nright: {openValueX}", scale = 0.75), xAxis = list( title = amText( "difference", fontSize = 17, fontWeight = "bold", fontFamily = "Helvetica" ), gridLines = amLine("darkblue", width = 2, opacity = 0.8, dash = "2,2"), breaks = amAxisBreaks(c(0,10,20,30)) ), yAxis = list( title = amText( "comparison", fontSize = 17, fontWeight = "bold", fontFamily = "Helvetica" ), labels = amAxisLabels(fontSize = 15), gridLines = amLine(color = "red", width = 1, opacity = 0.6, dash = "1,3") ), backgroundColor = "lightsalmon" )
set.seed(666) lwr <- rpois(20, 5) dat <- data.frame( comparison = paste0("Ctrl vs. ", LETTERS[1:20]), lwr = lwr, upr = lwr + rpois(20, 10) ) amHorizontalDumbbellChart( width = "500px", height = "450px", data = dat, draggable = TRUE, category = "comparison", values = rbind(c("lwr", "upr")), xLimits = c(0, 30), segmentsStyle = amSegment(width = 1, color = "darkred"), bullets = amCircle(strokeWidth = 0, color = "darkred"), tooltip = amTooltip("left: {valueX}\nright: {openValueX}", scale = 0.75), xAxis = list( title = amText( "difference", fontSize = 17, fontWeight = "bold", fontFamily = "Helvetica" ), gridLines = amLine("darkblue", width = 2, opacity = 0.8, dash = "2,2"), breaks = amAxisBreaks(c(0,10,20,30)) ), yAxis = list( title = amText( "comparison", fontSize = 17, fontWeight = "bold", fontFamily = "Helvetica" ), labels = amAxisLabels(fontSize = 15), gridLines = amLine(color = "red", width = 1, opacity = 0.6, dash = "1,3") ), backgroundColor = "lightsalmon" )
Create a list of settings for an image.
amImage(href, width, height, opacity = 1)
amImage(href, width, height, opacity = 1)
href |
a link to an image file or a base64 string representing an
image; you can get such a string with |
width , height
|
dimensions of the image |
opacity |
opacity of the image, a number between 0 and 1 |
A list of settings for an image.
Create a list of settings for a legend.
amLegend( position = "bottom", maxHeight = NULL, scrollable = FALSE, maxWidth = 220, itemsWidth = 20, itemsHeight = 20 )
amLegend( position = "bottom", maxHeight = NULL, scrollable = FALSE, maxWidth = 220, itemsWidth = 20, itemsHeight = 20 )
position |
legend position |
maxHeight |
maximum height for a horizontal legend
( |
scrollable |
whether a vertical legend should be scrollable |
maxWidth |
maximum width for a vertical legend
( |
itemsWidth |
width of the legend items |
itemsHeight |
height of the legend items |
A list of settings for a legend.
Create a list of settings for a line.
amLine( color = NULL, opacity = 1, width = 3, dash = NULL, tensionX = NULL, tensionY = NULL )
amLine( color = NULL, opacity = 1, width = 3, dash = NULL, tensionX = NULL, tensionY = NULL )
color |
line color |
opacity |
line opacity, a number between 0 and 1 |
width |
line width |
dash |
string defining a dashed/dotted line; see Dotted and dashed lines |
tensionX , tensionY
|
parameters for the smoothing; see Smoothed lines for the meaning of these parameters |
A list of settings for a line.
A color can be given by the name of a R color, the name of a CSS
color, e.g. "transparent"
or "fuchsia"
, an HEX code like
"#ff009a"
, a RGB code like "rgb(255,100,39)"
, or a HSL code
like "hsl(360,11,255)"
.
Create a HTML widget displaying a line chart.
amLineChart( data, data2 = NULL, xValue, yValues, yValueNames = NULL, hline = NULL, vline = NULL, xLimits = NULL, yLimits = NULL, expandX = 0, expandY = 5, Xformatter = ifelse(isDate, "yyyy-MM-dd", "#."), Yformatter = "#.", trend = FALSE, chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, bullets = NULL, alwaysShowBullets = FALSE, lineStyle = NULL, backgroundColor = NULL, xAxis = NULL, yAxis = NULL, scrollbarX = FALSE, scrollbarY = FALSE, legend = NULL, caption = NULL, image = NULL, button = NULL, cursor = FALSE, zoomButtons = FALSE, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
amLineChart( data, data2 = NULL, xValue, yValues, yValueNames = NULL, hline = NULL, vline = NULL, xLimits = NULL, yLimits = NULL, expandX = 0, expandY = 5, Xformatter = ifelse(isDate, "yyyy-MM-dd", "#."), Yformatter = "#.", trend = FALSE, chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, bullets = NULL, alwaysShowBullets = FALSE, lineStyle = NULL, backgroundColor = NULL, xAxis = NULL, yAxis = NULL, scrollbarX = FALSE, scrollbarY = FALSE, legend = NULL, caption = NULL, image = NULL, button = NULL, cursor = FALSE, zoomButtons = FALSE, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
data |
a dataframe |
data2 |
|
xValue |
name of the column of |
yValues |
name(s) of the column(s) of |
yValueNames |
names of the variables on the y-axis, to appear in the
legend; |
hline |
an optional horizontal line to add to the chart; it must be a
named list of the form |
vline |
an optional vertical line to add to the chart; it must be a
named list of the form |
xLimits |
range of the x-axis, a vector of two values specifying the
left and right limits of the x-axis; |
yLimits |
range of the y-axis, a vector of two values specifying the
lower and the upper limits of the y-axis; |
expandX |
if |
expandY |
if |
Xformatter |
a
number formatting string
if |
Yformatter |
a
number formatting string;
it is used to format the values displayed in the cursor tooltips if
|
trend |
option to request trend lines and to set their settings;
it is also possible to request the same kind of trend lines for all series
given by the |
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
draggable |
|
tooltip |
settings of the tooltips; |
bullets |
settings of the bullets; |
alwaysShowBullets |
logical, whether the bullets should always be visible, or visible on hover only |
lineStyle |
settings of the lines; |
backgroundColor |
a color for the chart background; it can be given by
the name of a R color, the name of a CSS
color, e.g. |
xAxis |
settings of the x-axis given as a list, or just a string
for the axis title; the list of settings has five possible fields:
a field |
yAxis |
settings of the y-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 x-axis |
scrollbarY |
logical, whether to add a scrollbar for the y-axis |
legend |
|
caption |
|
image |
option to include an image at a corner of the chart;
|
button |
|
cursor |
option to add a cursor on the chart; |
zoomButtons |
a Boolean value, or a list created with
|
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 |
# a line chart with a numeric x-axis #### set.seed(666) dat <- data.frame( x = 1:10, y1 = rnorm(10), y2 = rnorm(10) ) amLineChart( data = dat, width = "700px", xValue = "x", yValues = c("y1", "y2"), yValueNames = list(y1 = "Sample 1", y2 = "Sample 2"), trend = list( y1 = list( method = "lm.js", order = 3, style = amLine(color = "lightyellow", dash = "3,2") ), y2 = list( method = "loess", style = amLine(color = "palevioletred", dash = "3,2") ) ), draggable = list(y1 = TRUE, y2 = FALSE), backgroundColor = "#30303d", tooltip = amTooltip( text = "[bold]({valueX},{valueY})[/]", textColor = "white", backgroundColor = "#101010", borderColor = "whitesmoke" ), bullets = list( y1 = amCircle(color = "yellow", strokeColor = "olive"), y2 = amCircle(color = "orangered", strokeColor = "darkred") ), alwaysShowBullets = TRUE, cursor = list( extraTooltipPrecision = list(x = 0, y = 2), modifier = list( y = c( "var value = parseFloat(text);", "var style = value > 0 ? '[#0000ff]' : '[#ff0000]';", "text = style + text + '[/]';" ) ) ), lineStyle = list( y1 = amLine(color = "yellow", width = 4), y2 = amLine(color = "orangered", width = 4) ), chartTitle = amText( text = "Gaussian samples", color = "whitesmoke", fontWeight = "bold" ), xAxis = list(title = amText(text = "Observation", fontSize = 21, color = "silver", fontWeight = "bold"), labels = amAxisLabels(fontSize = 17), breaks = amAxisBreaks( values = 1:10, labels = sprintf("[bold %s]%d[/]", rainbow(10), 1:10))), yAxis = list(title = amText(text = "Value", fontSize = 21, color = "silver", fontWeight = "bold"), labels = amAxisLabels(color = "whitesmoke", fontSize = 14), gridLines = amLine(color = "whitesmoke", opacity = 0.4, width = 1)), yLimits = c(-3, 3), Yformatter = "#.00", caption = amText(text = "[font-style:italic]try to drag the yellow line![/]", color = "yellow"), theme = "dark") # line chart with a date x-axis #### library(lubridate) set.seed(666) dat <- data.frame( date = ymd(180101) + days(0:60), visits = rpois(61, 20) ) amLineChart( data = dat, width = "750px", xValue = "date", yValues = "visits", draggable = TRUE, chartTitle = "Number of visits", xAxis = list( title = "Date", labels = amAxisLabels( formatter = amDateAxisFormatter( day = c("dt", "[bold]MMM[/] dt"), week = c("dt", "[bold]MMM[/] dt") ) ), breaks = amAxisBreaks(timeInterval = "7 days") ), yAxis = "Visits", xLimits = range(dat$date) + c(0,7), yLimits = c(0, 35), backgroundColor = "whitesmoke", tooltip = paste0( "[bold][font-style:italic]{dateX.value.formatDate('yyyy/MM/dd')}[/]", "\nvisits: {valueY}[/]" ), caption = amText(text = "Year 2018"), theme = "material") # smoothed lines #### x <- seq(-4, 4, length.out = 100) dat <- data.frame( x = x, Gauss = dnorm(x), Cauchy = dcauchy(x) ) amLineChart( data = dat, width = "700px", xValue = "x", yValues = c("Gauss", "Cauchy"), yValueNames = list( Gauss = "Standard normal distribution", Cauchy = "Cauchy distribution" ), draggable = FALSE, tooltip = FALSE, lineStyle = amLine( width = 4, tensionX = 0.8, tensionY = 0.8 ), xAxis = list(title = amText(text = "x", fontSize = 21, color = "navyblue"), labels = amAxisLabels( color = "midnightblue", fontSize = 17)), yAxis = list(title = amText(text = "density", fontSize = 21, color = "navyblue"), labels = FALSE), theme = "dataviz")
# a line chart with a numeric x-axis #### set.seed(666) dat <- data.frame( x = 1:10, y1 = rnorm(10), y2 = rnorm(10) ) amLineChart( data = dat, width = "700px", xValue = "x", yValues = c("y1", "y2"), yValueNames = list(y1 = "Sample 1", y2 = "Sample 2"), trend = list( y1 = list( method = "lm.js", order = 3, style = amLine(color = "lightyellow", dash = "3,2") ), y2 = list( method = "loess", style = amLine(color = "palevioletred", dash = "3,2") ) ), draggable = list(y1 = TRUE, y2 = FALSE), backgroundColor = "#30303d", tooltip = amTooltip( text = "[bold]({valueX},{valueY})[/]", textColor = "white", backgroundColor = "#101010", borderColor = "whitesmoke" ), bullets = list( y1 = amCircle(color = "yellow", strokeColor = "olive"), y2 = amCircle(color = "orangered", strokeColor = "darkred") ), alwaysShowBullets = TRUE, cursor = list( extraTooltipPrecision = list(x = 0, y = 2), modifier = list( y = c( "var value = parseFloat(text);", "var style = value > 0 ? '[#0000ff]' : '[#ff0000]';", "text = style + text + '[/]';" ) ) ), lineStyle = list( y1 = amLine(color = "yellow", width = 4), y2 = amLine(color = "orangered", width = 4) ), chartTitle = amText( text = "Gaussian samples", color = "whitesmoke", fontWeight = "bold" ), xAxis = list(title = amText(text = "Observation", fontSize = 21, color = "silver", fontWeight = "bold"), labels = amAxisLabels(fontSize = 17), breaks = amAxisBreaks( values = 1:10, labels = sprintf("[bold %s]%d[/]", rainbow(10), 1:10))), yAxis = list(title = amText(text = "Value", fontSize = 21, color = "silver", fontWeight = "bold"), labels = amAxisLabels(color = "whitesmoke", fontSize = 14), gridLines = amLine(color = "whitesmoke", opacity = 0.4, width = 1)), yLimits = c(-3, 3), Yformatter = "#.00", caption = amText(text = "[font-style:italic]try to drag the yellow line![/]", color = "yellow"), theme = "dark") # line chart with a date x-axis #### library(lubridate) set.seed(666) dat <- data.frame( date = ymd(180101) + days(0:60), visits = rpois(61, 20) ) amLineChart( data = dat, width = "750px", xValue = "date", yValues = "visits", draggable = TRUE, chartTitle = "Number of visits", xAxis = list( title = "Date", labels = amAxisLabels( formatter = amDateAxisFormatter( day = c("dt", "[bold]MMM[/] dt"), week = c("dt", "[bold]MMM[/] dt") ) ), breaks = amAxisBreaks(timeInterval = "7 days") ), yAxis = "Visits", xLimits = range(dat$date) + c(0,7), yLimits = c(0, 35), backgroundColor = "whitesmoke", tooltip = paste0( "[bold][font-style:italic]{dateX.value.formatDate('yyyy/MM/dd')}[/]", "\nvisits: {valueY}[/]" ), caption = amText(text = "Year 2018"), theme = "material") # smoothed lines #### x <- seq(-4, 4, length.out = 100) dat <- data.frame( x = x, Gauss = dnorm(x), Cauchy = dcauchy(x) ) amLineChart( data = dat, width = "700px", xValue = "x", yValues = c("Gauss", "Cauchy"), yValueNames = list( Gauss = "Standard normal distribution", Cauchy = "Cauchy distribution" ), draggable = FALSE, tooltip = FALSE, lineStyle = amLine( width = 4, tensionX = 0.8, tensionY = 0.8 ), xAxis = list(title = amText(text = "x", fontSize = 21, color = "navyblue"), labels = amAxisLabels( color = "midnightblue", fontSize = 17)), yAxis = list(title = amText(text = "density", fontSize = 21, color = "navyblue"), labels = FALSE), theme = "dataviz")
Create a HTML widget displaying a 100% stacked bar chart.
amPercentageBarChart( data, category, values, valueNames = NULL, hline = NULL, chartTitle = NULL, theme = NULL, animated = TRUE, backgroundColor = NULL, xAxis = NULL, yAxis = NULL, scrollbarX = FALSE, scrollbarY = FALSE, legend = TRUE, caption = NULL, image = NULL, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
amPercentageBarChart( data, category, values, valueNames = NULL, hline = NULL, chartTitle = NULL, theme = NULL, animated = TRUE, backgroundColor = NULL, xAxis = NULL, yAxis = NULL, scrollbarX = FALSE, scrollbarY = FALSE, legend = TRUE, caption = NULL, image = NULL, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
data |
a dataframe |
category |
name of the column of |
values |
names of the columns of |
valueNames |
names of the values variables, to appear in the legend;
|
hline |
an optional horizontal line to add to the chart; it must be a
named list of the form |
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
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.
|
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;
|
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 |
library(rAmCharts4) dat <- data.frame( category = c("A", "B", "C"), v1 = c(1, 2, 3), v2 = c(9, 5, 7) ) amPercentageBarChart( dat, category = "category", values = c("v1", "v2"), valueNames = c("Value1", "Value2"), yAxis = "Percentage", theme = "dataviz", legend = amLegend(position = "right") )
library(rAmCharts4) dat <- data.frame( category = c("A", "B", "C"), v1 = c(1, 2, 3), v2 = c(9, 5, 7) ) amPercentageBarChart( dat, category = "category", values = c("v1", "v2"), valueNames = c("Value1", "Value2"), yAxis = "Percentage", theme = "dataviz", legend = amLegend(position = "right") )
Create a HTML widget displaying a pie chart.
amPieChart( data, category, value, innerRadius = 0, threeD = FALSE, depth = ifelse(variableDepth, 100, 10), colorStep = 3, variableRadius = FALSE, variableDepth = FALSE, chartTitle = NULL, theme = NULL, animated = TRUE, backgroundColor = NULL, legend = TRUE, caption = NULL, image = NULL, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
amPieChart( data, category, value, innerRadius = 0, threeD = FALSE, depth = ifelse(variableDepth, 100, 10), colorStep = 3, variableRadius = FALSE, variableDepth = FALSE, chartTitle = NULL, theme = NULL, animated = TRUE, backgroundColor = NULL, legend = TRUE, caption = NULL, image = NULL, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
data |
a dataframe |
category |
name of the column of |
value |
name of the column of |
innerRadius |
the inner radius of the pie chart in percent |
threeD |
whether to render a 3D pie chart |
depth |
for a 3D chart, this parameter controls the height of the slices |
colorStep |
the step in the color palette |
variableRadius |
whether to render slices with variable radius |
variableDepth |
for a 3D chart, whether to render slices with variable depth |
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
backgroundColor |
a color for the chart background; it can be
given by the name of a R color, the name of a CSS color, e.g.
|
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;
|
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 |
library(rAmCharts4) dat <- data.frame( country = c( "Lithuania", "Czechia", "Ireland", "Germany", "Australia", "Austria" ), value = c(260, 230, 200, 165, 139, 128) ) amPieChart( data = dat, category = "country", value = "value", variableRadius = TRUE ) # shiny app demonstrating the options #### library(rAmCharts4) library(shiny) dat <- data.frame( country = c( "Lithuania", "Czechia", "Ireland", "Germany", "Australia", "Austria" ), value = c(260, 230, 200, 165, 139, 128) ) ui <- fluidPage( sidebarLayout( sidebarPanel( sliderInput( "innerRadius", "Inner radius", min = 0, max = 60, value = 0, step = 20 ), checkboxInput("variableRadius", "Variable radius", TRUE), checkboxInput("threeD", "3D"), conditionalPanel( "input.threeD", checkboxInput("variableDepth", "Variable depth") ) ), mainPanel( amChart4Output("piechart", height = "500px") ) ) ) server <- function(input, output, session){ piechart <- reactive({ amPieChart( data = dat, category = "country", value = "value", innerRadius = input[["innerRadius"]], threeD = input[["threeD"]], variableDepth = input[["variableDepth"]], depth = ifelse(input[["variableDepth"]], 300, 10), variableRadius = input[["variableRadius"]], theme = "dark" ) }) output[["piechart"]] <- renderAmChart4({ piechart() }) } if(interactive()){ shinyApp(ui, server) }
library(rAmCharts4) dat <- data.frame( country = c( "Lithuania", "Czechia", "Ireland", "Germany", "Australia", "Austria" ), value = c(260, 230, 200, 165, 139, 128) ) amPieChart( data = dat, category = "country", value = "value", variableRadius = TRUE ) # shiny app demonstrating the options #### library(rAmCharts4) library(shiny) dat <- data.frame( country = c( "Lithuania", "Czechia", "Ireland", "Germany", "Australia", "Austria" ), value = c(260, 230, 200, 165, 139, 128) ) ui <- fluidPage( sidebarLayout( sidebarPanel( sliderInput( "innerRadius", "Inner radius", min = 0, max = 60, value = 0, step = 20 ), checkboxInput("variableRadius", "Variable radius", TRUE), checkboxInput("threeD", "3D"), conditionalPanel( "input.threeD", checkboxInput("variableDepth", "Variable depth") ) ), mainPanel( amChart4Output("piechart", height = "500px") ) ) ) server <- function(input, output, session){ piechart <- reactive({ amPieChart( data = dat, category = "country", value = "value", innerRadius = input[["innerRadius"]], threeD = input[["threeD"]], variableDepth = input[["variableDepth"]], depth = ifelse(input[["variableDepth"]], 300, 10), variableRadius = input[["variableRadius"]], theme = "dark" ) }) output[["piechart"]] <- renderAmChart4({ piechart() }) } if(interactive()){ shinyApp(ui, server) }
Create a HTML widget displaying a radial bar chart.
amRadialBarChart( data, data2 = NULL, category, values, valueNames = NULL, showValues = TRUE, innerRadius = 50, yLimits = NULL, expandY = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, columnStyle = NULL, 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 )
amRadialBarChart( data, data2 = NULL, category, values, valueNames = NULL, showValues = TRUE, innerRadius = 50, yLimits = NULL, expandY = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, columnStyle = NULL, 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 )
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 |
innerRadius |
inner radius of the chart, a percentage (between 0 and 100 theoretically, but in practice it should be between 30 and 70) |
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; |
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 |
# a grouped radial 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) ) amRadialBarChart( data = dat, data2 = dat, width = "600px", height = "600px", category = "country", values = c("income", "expenses"), valueNames = list(income = "Income", expenses = "Expenses"), showValues = FALSE, tooltip = amTooltip( textColor = "white", backgroundColor = "#101010", borderColor = "silver" ), draggable = TRUE, backgroundColor = "#30303d", columnStyle = list( income = amColumn( color = "darkmagenta", strokeColor = "#cccccc", strokeWidth = 2 ), expenses = amColumn( color = "darkred", strokeColor = "#cccccc", strokeWidth = 2 ) ), chartTitle = "Income and expenses per country", xAxis = list( labels = amAxisLabelsCircular( radius = -82, relativeRotation = 90 ) ), yAxis = list( labels = amAxisLabels(color = "orange"), gridLines = amLine(color = "whitesmoke", width = 1, opacity = 0.4), breaks = amAxisBreaks(values = seq(0, 40, by = 10)) ), yLimits = c(0, 40), valueFormatter = "#.#", caption = amText( text = "Year 2018", fontFamily = "Impact", fontSize = 18 ), theme = "dark") # just for fun #### dat <- data.frame( cluster = letters[1:6], y1 = rep(10, 6), y2 = rep(8, 6), y3 = rep(6, 6), y4 = rep(4, 6), y5 = rep(2, 6), y6 = rep(4, 6), y7 = rep(6, 6), y8 = rep(8, 6), y9 = rep(10, 6) ) amRadialBarChart( data = dat, width = "500px", height = "500px", innerRadius = 10, category = "cluster", values = paste0("y", 1:9), showValues = FALSE, tooltip = FALSE, draggable = FALSE, backgroundColor = "black", columnStyle = amColumn(strokeWidth = 1, strokeColor = "white"), cellWidth = 96, xAxis = list(labels = FALSE), yAxis = list(labels = FALSE, gridLines = FALSE), yLimits = c(0, 10), legend = FALSE, theme = "kelly")
# a grouped radial 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) ) amRadialBarChart( data = dat, data2 = dat, width = "600px", height = "600px", category = "country", values = c("income", "expenses"), valueNames = list(income = "Income", expenses = "Expenses"), showValues = FALSE, tooltip = amTooltip( textColor = "white", backgroundColor = "#101010", borderColor = "silver" ), draggable = TRUE, backgroundColor = "#30303d", columnStyle = list( income = amColumn( color = "darkmagenta", strokeColor = "#cccccc", strokeWidth = 2 ), expenses = amColumn( color = "darkred", strokeColor = "#cccccc", strokeWidth = 2 ) ), chartTitle = "Income and expenses per country", xAxis = list( labels = amAxisLabelsCircular( radius = -82, relativeRotation = 90 ) ), yAxis = list( labels = amAxisLabels(color = "orange"), gridLines = amLine(color = "whitesmoke", width = 1, opacity = 0.4), breaks = amAxisBreaks(values = seq(0, 40, by = 10)) ), yLimits = c(0, 40), valueFormatter = "#.#", caption = amText( text = "Year 2018", fontFamily = "Impact", fontSize = 18 ), theme = "dark") # just for fun #### dat <- data.frame( cluster = letters[1:6], y1 = rep(10, 6), y2 = rep(8, 6), y3 = rep(6, 6), y4 = rep(4, 6), y5 = rep(2, 6), y6 = rep(4, 6), y7 = rep(6, 6), y8 = rep(8, 6), y9 = rep(10, 6) ) amRadialBarChart( data = dat, width = "500px", height = "500px", innerRadius = 10, category = "cluster", values = paste0("y", 1:9), showValues = FALSE, tooltip = FALSE, draggable = FALSE, backgroundColor = "black", columnStyle = amColumn(strokeWidth = 1, strokeColor = "white"), cellWidth = 96, xAxis = list(labels = FALSE), yAxis = list(labels = FALSE, gridLines = FALSE), yLimits = c(0, 10), legend = FALSE, theme = "kelly")
Create a HTML widget displaying a range area chart.
amRangeAreaChart( data, data2 = NULL, xValue, yValues, areas = NULL, hline = NULL, vline = NULL, xLimits = NULL, yLimits = NULL, expandX = 0, expandY = 5, Xformatter = ifelse(isDate, "yyyy-MM-dd", "#."), Yformatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, bullets = NULL, alwaysShowBullets = FALSE, lineStyle = NULL, backgroundColor = 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 )
amRangeAreaChart( data, data2 = NULL, xValue, yValues, areas = NULL, hline = NULL, vline = NULL, xLimits = NULL, yLimits = NULL, expandX = 0, expandY = 5, Xformatter = ifelse(isDate, "yyyy-MM-dd", "#."), Yformatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, bullets = NULL, alwaysShowBullets = FALSE, lineStyle = NULL, backgroundColor = 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 )
data |
a dataframe |
data2 |
|
xValue |
name of the column of |
yValues |
a character matrix with two columns; each row corresponds to
a range area and provides the names of two columns of |
areas |
an unnamed list of list of settings for the range areas; the
n-th inner list of settings corresponds to the n-th row of the
|
hline |
an optional horizontal line to add to the chart; it must be a
named list of the form |
vline |
an optional vertical line to add to the chart; it must be a
named list of the form |
xLimits |
range of the x-axis, a vector of two values specifying
the left and right limits of the x-axis; |
yLimits |
range of the y-axis, a vector of two values specifying
the lower and upper limits of the y-axis; |
expandX |
if |
expandY |
if |
Xformatter |
a
number formatting string
if |
Yformatter |
a
number formatting string;
it is used to format the values displayed in the cursor tooltips 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; |
bullets |
settings of the bullets; |
alwaysShowBullets |
logical, whether the bullets should always be visible, or visible on hover only |
lineStyle |
settings of the lines; |
backgroundColor |
a color for the chart background |
xAxis |
settings of the x-axis given as a list, or just a string
for the axis title; the list of settings has five possible fields:
a field |
yAxis |
settings of the y-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 x-axis |
scrollbarY |
logical, whether to add a scrollbar for the y-axis |
legend |
|
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 |
A color can be given by the name of a R color, the name of a CSS
color, e.g. "crimson"
or "silver"
, an HEX code like
"#ff009a"
, a RGB code like "rgb(255,100,39)"
, or a HSL code
like "hsl(360,11,255)"
.
set.seed(666) x <- 1:20 dat <- data.frame( x = x, y1 = rnorm(20, sd = 1.5), y2 = rnorm(20, 10, sd = 1.5), z1 = rnorm(20, x+5, sd = 1.5), z2 = rnorm(20, x+15, sd = 1.5) ) amRangeAreaChart( data = dat, width = "700px", xValue = "x", yValues = rbind(c("y1", "y2"), c("z1", "z2")), xLimits = c(1, 20), draggable = TRUE, backgroundColor = "#30303d", tooltip = list( y1 = amTooltip( text = "[bold]upper: {openValueY}\nlower: {valueY}[/]", textColor = "yellow", backgroundColor = "darkmagenta", backgroundOpacity = 0.8, borderColor = "rebeccapurple", scale = 0.9 ), y2 = amTooltip( text = "[bold]upper: {valueY}\nlower: {openValueY}[/]", textColor = "yellow", backgroundColor = "darkmagenta", backgroundOpacity = 0.8, borderColor = "rebeccapurple", scale = 0.9 ), z1 = amTooltip( text = "[bold]upper: {openValueY}\nlower: {valueY}[/]", textColor = "white", backgroundColor = "darkred", backgroundOpacity = 0.8, borderColor = "crimson", scale = 0.9 ), z2 = amTooltip( text = "[bold]upper: {valueY}\nlower: {openValueY}[/]", textColor = "white", backgroundColor = "darkred", backgroundOpacity = 0.8, borderColor = "crimson", scale = 0.9 ) ), bullets = list( y1 = amCircle(color = "yellow", strokeColor = "olive"), y2 = amCircle(color = "yellow", strokeColor = "olive"), z1 = amCircle(color = "orangered", strokeColor = "darkred"), z2 = amCircle(color = "orangered", strokeColor = "darkred") ), alwaysShowBullets = FALSE, lineStyle = list( y1 = amLine(color = "yellow", width = 3, tensionX = 0.8, tensionY = 0.8), y2 = amLine(color = "yellow", width = 3, tensionX = 0.8, tensionY = 0.8), z1 = amLine(color = "orangered", width = 3, tensionX = 0.8, tensionY = 0.8), z2 = amLine(color = "orangered", width = 3, tensionX = 0.8, tensionY = 0.8) ), areas = list( list(name = "y1-y2", color = "blue", opacity = 0.2), list(name = "z1-z2", color = "red", opacity = 0.2) ), cursor = list( tooltip = amTooltip( backgroundColor = "silver" ), extraTooltipPrecision = list(x = 0, y = 2), modifier = list(y = "text = parseFloat(text).toFixed(2);") ), chartTitle = amText(text = "Range area chart", color = "whitesmoke", fontWeight = "bold"), xAxis = list(title = amText(text = "Observation", fontSize = 20, color = "silver"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17), adjust = 5), yAxis = list(title = amText(text = "Value", fontSize = 20, color = "silver"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17), gridLines = amLine(color = "antiquewhite", opacity = 0.4, width = 1)), Xformatter = "#", Yformatter = "#.00", image = list( image = amImage( href = tinyIcon("react", backgroundColor = "transparent"), width = 40, height = 40 ), position = "bottomleft", hjust = 2, vjust = -2 ), theme = "dark")
set.seed(666) x <- 1:20 dat <- data.frame( x = x, y1 = rnorm(20, sd = 1.5), y2 = rnorm(20, 10, sd = 1.5), z1 = rnorm(20, x+5, sd = 1.5), z2 = rnorm(20, x+15, sd = 1.5) ) amRangeAreaChart( data = dat, width = "700px", xValue = "x", yValues = rbind(c("y1", "y2"), c("z1", "z2")), xLimits = c(1, 20), draggable = TRUE, backgroundColor = "#30303d", tooltip = list( y1 = amTooltip( text = "[bold]upper: {openValueY}\nlower: {valueY}[/]", textColor = "yellow", backgroundColor = "darkmagenta", backgroundOpacity = 0.8, borderColor = "rebeccapurple", scale = 0.9 ), y2 = amTooltip( text = "[bold]upper: {valueY}\nlower: {openValueY}[/]", textColor = "yellow", backgroundColor = "darkmagenta", backgroundOpacity = 0.8, borderColor = "rebeccapurple", scale = 0.9 ), z1 = amTooltip( text = "[bold]upper: {openValueY}\nlower: {valueY}[/]", textColor = "white", backgroundColor = "darkred", backgroundOpacity = 0.8, borderColor = "crimson", scale = 0.9 ), z2 = amTooltip( text = "[bold]upper: {valueY}\nlower: {openValueY}[/]", textColor = "white", backgroundColor = "darkred", backgroundOpacity = 0.8, borderColor = "crimson", scale = 0.9 ) ), bullets = list( y1 = amCircle(color = "yellow", strokeColor = "olive"), y2 = amCircle(color = "yellow", strokeColor = "olive"), z1 = amCircle(color = "orangered", strokeColor = "darkred"), z2 = amCircle(color = "orangered", strokeColor = "darkred") ), alwaysShowBullets = FALSE, lineStyle = list( y1 = amLine(color = "yellow", width = 3, tensionX = 0.8, tensionY = 0.8), y2 = amLine(color = "yellow", width = 3, tensionX = 0.8, tensionY = 0.8), z1 = amLine(color = "orangered", width = 3, tensionX = 0.8, tensionY = 0.8), z2 = amLine(color = "orangered", width = 3, tensionX = 0.8, tensionY = 0.8) ), areas = list( list(name = "y1-y2", color = "blue", opacity = 0.2), list(name = "z1-z2", color = "red", opacity = 0.2) ), cursor = list( tooltip = amTooltip( backgroundColor = "silver" ), extraTooltipPrecision = list(x = 0, y = 2), modifier = list(y = "text = parseFloat(text).toFixed(2);") ), chartTitle = amText(text = "Range area chart", color = "whitesmoke", fontWeight = "bold"), xAxis = list(title = amText(text = "Observation", fontSize = 20, color = "silver"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17), adjust = 5), yAxis = list(title = amText(text = "Value", fontSize = 20, color = "silver"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17), gridLines = amLine(color = "antiquewhite", opacity = 0.4, width = 1)), Xformatter = "#", Yformatter = "#.00", image = list( image = amImage( href = tinyIcon("react", backgroundColor = "transparent"), width = 40, height = 40 ), position = "bottomleft", hjust = 2, vjust = -2 ), theme = "dark")
Create a HTML widget displaying a scatter chart.
amScatterChart( data, data2 = NULL, xValue, yValues, yValueNames = NULL, hline = NULL, vline = NULL, xLimits = NULL, yLimits = NULL, expandX = 0, expandY = 5, Xformatter = ifelse(isDate, "yyyy-MM-dd", "#."), Yformatter = "#.", trend = FALSE, chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, pointsStyle = NULL, backgroundColor = NULL, xAxis = NULL, yAxis = NULL, scrollbarX = FALSE, scrollbarY = FALSE, legend = NULL, caption = NULL, image = NULL, button = NULL, cursor = FALSE, zoomButtons = FALSE, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
amScatterChart( data, data2 = NULL, xValue, yValues, yValueNames = NULL, hline = NULL, vline = NULL, xLimits = NULL, yLimits = NULL, expandX = 0, expandY = 5, Xformatter = ifelse(isDate, "yyyy-MM-dd", "#."), Yformatter = "#.", trend = FALSE, chartTitle = NULL, theme = NULL, animated = TRUE, draggable = FALSE, tooltip = NULL, pointsStyle = NULL, backgroundColor = NULL, xAxis = NULL, yAxis = NULL, scrollbarX = FALSE, scrollbarY = FALSE, legend = NULL, caption = NULL, image = NULL, button = NULL, cursor = FALSE, zoomButtons = FALSE, width = NULL, height = NULL, export = FALSE, chartId = NULL, elementId = NULL )
data |
a dataframe |
data2 |
|
xValue |
name of the column of |
yValues |
name(s) of the column(s) of |
yValueNames |
names of the variables on the y-axis,
to appear in the legend;
|
hline |
an optional horizontal line to add to the chart; it must be a
named list of the form |
vline |
an optional vertical line to add to the chart; it must be a
named list of the form |
xLimits |
range of the x-axis, a vector of two values specifying
the left and the right limits of the x-axis; |
yLimits |
range of the y-axis, a vector of two values specifying
the lower and the upper limits of the y-axis; |
expandX |
if |
expandY |
if |
Xformatter |
a
number formatting string
if |
Yformatter |
a
number formatting string;
it is used to format the values displayed in the cursor tooltips if
|
trend |
option to request trend lines and to set their settings;
it is also possible to request the same kind of trend lines for all series
given by the |
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
draggable |
|
tooltip |
settings of the tooltips; |
pointsStyle |
settings of the points style; |
backgroundColor |
a color for the chart background; it can be given by
the name of a R color, the name of a CSS
color, e.g. |
xAxis |
settings of the x-axis given as a list, or just a string
for the axis title; the list of settings has five possible fields:
a field |
yAxis |
settings of the y-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 x-axis |
scrollbarY |
logical, whether to add a scrollbar for the y-axis |
legend |
|
caption |
|
image |
option to include an image at a corner of the chart;
|
button |
|
cursor |
option to add a cursor on the chart; |
zoomButtons |
a Boolean value, or a list created with
|
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 |
# iris data: petal widths #### dat <- iris dat$obs <- rep(1:50, 3) dat <- reshape2::dcast(dat, obs ~ Species, value.var = "Petal.Width") amScatterChart( data = dat, width = "700px", xValue = "obs", yValues = c("setosa", "versicolor", "virginica"), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = list( setosa = amCircle(color = "orange", strokeColor = "red"), versicolor = amCircle(color = "cyan", strokeColor = "blue"), virginica = amCircle(color = "palegreen", strokeColor = "darkgreen") ), tooltip = "obs: {valueX}\nvalue: {valueY}", chartTitle = amText(text = "Iris data", color = "whitesmoke"), xAxis = list(title = amText(text = "Observation", fontSize = 21, color = "silver"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17)), yAxis = list(title = amText(text = "Petal width", fontSize = 21, color = "silver"), labels = amAxisLabels(color = "whitesmoke", fontSize = 14), gridLines = amLine(color = "whitesmoke", opacity = 0.4, width = 1)), Xformatter = "#", Yformatter = "#.0", caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark") # iris data: petal widths vs petal lengths dat <- iris dat$obs <- rep(1:50, 3) dat <- reshape2::dcast(dat, obs + Petal.Length ~ Species, value.var = "Petal.Width") amScatterChart( data = dat, width = "700px", xValue = "Petal.Length", yValues = c("setosa", "versicolor", "virginica"), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = list( setosa = amCircle(color = "orange", strokeColor = "red"), versicolor = amCircle(color = "cyan", strokeColor = "blue"), virginica = amCircle(color = "palegreen", strokeColor = "darkgreen") ), tooltip = list( setosa = amTooltip( text = "length: {valueX}\nwidth: {valueY}", backgroundColor = "orange", borderColor = "red", textColor = "black" ), versicolor = amTooltip( text = "length: {valueX}\nwidth: {valueY}", backgroundColor = "cyan", borderColor = "blue", textColor = "black" ), virginica = amTooltip( text = "length: {valueX}\nwidth: {valueY}", backgroundColor = "palegreen", borderColor = "darkgreen", textColor = "black" ) ), chartTitle = amText(text = "Iris data", color = "silver"), xAxis = list(title = amText(text = "Petal length", fontSize = 19, color = "gold"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17)), yAxis = list(title = amText(text = "Petal width", fontSize = 19, color = "gold"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17), gridLines = amLine(color = "whitesmoke", opacity = 0.4, width = 1)), cursor = list( tooltip = amTooltip(backgroundColor = "lightgray"), extraTooltipPrecision = list(x = 1, y = 1) ), caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark") # scatter chart with trend lines #### Asym = 5; R0 = 1; lrc = -3/4 x <- seq(-.3, 5, len = 101) y0 <- Asym + (R0-Asym) * exp(-exp(lrc)* x) dat <- data.frame( x = x, y1 = y0 + rnorm(101, sd = 0.33), y2 = y0 + rnorm(101, sd = 0.33) + 2 ) amScatterChart( data = dat, width = "700px", xValue = "x", yValues = c("y1", "y2"), trend = list("_all" = list( method = "nls", formula = y ~ SSasymp(x, Asym, R0, lrc), style = amLine() )), draggable = FALSE, pointsStyle = list( y1 = amTriangle( width = 8, height = 8, strokeColor = "yellow", strokeWidth = 1 ), y2 = amTriangle( width = 8, height = 8, strokeColor = "chartreuse", strokeWidth = 1, rotation = 180 ) ), chartTitle = amText(text = "Asymptotic regression model"), xAxis = "x", yAxis = "y", Xformatter = "#.###", Yformatter = "#.", theme = "kelly", zoomButtons = TRUE)
# iris data: petal widths #### dat <- iris dat$obs <- rep(1:50, 3) dat <- reshape2::dcast(dat, obs ~ Species, value.var = "Petal.Width") amScatterChart( data = dat, width = "700px", xValue = "obs", yValues = c("setosa", "versicolor", "virginica"), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = list( setosa = amCircle(color = "orange", strokeColor = "red"), versicolor = amCircle(color = "cyan", strokeColor = "blue"), virginica = amCircle(color = "palegreen", strokeColor = "darkgreen") ), tooltip = "obs: {valueX}\nvalue: {valueY}", chartTitle = amText(text = "Iris data", color = "whitesmoke"), xAxis = list(title = amText(text = "Observation", fontSize = 21, color = "silver"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17)), yAxis = list(title = amText(text = "Petal width", fontSize = 21, color = "silver"), labels = amAxisLabels(color = "whitesmoke", fontSize = 14), gridLines = amLine(color = "whitesmoke", opacity = 0.4, width = 1)), Xformatter = "#", Yformatter = "#.0", caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark") # iris data: petal widths vs petal lengths dat <- iris dat$obs <- rep(1:50, 3) dat <- reshape2::dcast(dat, obs + Petal.Length ~ Species, value.var = "Petal.Width") amScatterChart( data = dat, width = "700px", xValue = "Petal.Length", yValues = c("setosa", "versicolor", "virginica"), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = list( setosa = amCircle(color = "orange", strokeColor = "red"), versicolor = amCircle(color = "cyan", strokeColor = "blue"), virginica = amCircle(color = "palegreen", strokeColor = "darkgreen") ), tooltip = list( setosa = amTooltip( text = "length: {valueX}\nwidth: {valueY}", backgroundColor = "orange", borderColor = "red", textColor = "black" ), versicolor = amTooltip( text = "length: {valueX}\nwidth: {valueY}", backgroundColor = "cyan", borderColor = "blue", textColor = "black" ), virginica = amTooltip( text = "length: {valueX}\nwidth: {valueY}", backgroundColor = "palegreen", borderColor = "darkgreen", textColor = "black" ) ), chartTitle = amText(text = "Iris data", color = "silver"), xAxis = list(title = amText(text = "Petal length", fontSize = 19, color = "gold"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17)), yAxis = list(title = amText(text = "Petal width", fontSize = 19, color = "gold"), labels = amAxisLabels(color = "whitesmoke", fontSize = 17), gridLines = amLine(color = "whitesmoke", opacity = 0.4, width = 1)), cursor = list( tooltip = amTooltip(backgroundColor = "lightgray"), extraTooltipPrecision = list(x = 1, y = 1) ), caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark") # scatter chart with trend lines #### Asym = 5; R0 = 1; lrc = -3/4 x <- seq(-.3, 5, len = 101) y0 <- Asym + (R0-Asym) * exp(-exp(lrc)* x) dat <- data.frame( x = x, y1 = y0 + rnorm(101, sd = 0.33), y2 = y0 + rnorm(101, sd = 0.33) + 2 ) amScatterChart( data = dat, width = "700px", xValue = "x", yValues = c("y1", "y2"), trend = list("_all" = list( method = "nls", formula = y ~ SSasymp(x, Asym, R0, lrc), style = amLine() )), draggable = FALSE, pointsStyle = list( y1 = amTriangle( width = 8, height = 8, strokeColor = "yellow", strokeWidth = 1 ), y2 = amTriangle( width = 8, height = 8, strokeColor = "chartreuse", strokeWidth = 1, rotation = 180 ) ), chartTitle = amText(text = "Asymptotic regression model"), xAxis = "x", yAxis = "y", Xformatter = "#.###", Yformatter = "#.", theme = "kelly", zoomButtons = TRUE)
Create a list of settings for a segment.
amSegment(color = NULL, width = 1)
amSegment(color = NULL, width = 1)
color |
color of the segment; this can be a color adapter |
width |
width of the segment |
A list of settings for a segment.
A color can be given by the name of a R color, the name of a CSS
color, e.g. "lime"
or "indigo"
, an HEX code like
"#ff009a"
, a RGB code like "rgb(255,100,39)"
, or a HSL code
like "hsl(360,11,255)"
.
Create a HTML widget displaying a stacked bar chart.
amStackedBarChart( data, data2 = NULL, category, stacks, seriesNames = NULL, colors = NULL, hline = NULL, yLimits = NULL, expandY = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, tooltip = NULL, threeD = 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 )
amStackedBarChart( data, data2 = NULL, category, stacks, seriesNames = NULL, colors = NULL, hline = NULL, yLimits = NULL, expandY = 5, valueFormatter = "#.", chartTitle = NULL, theme = NULL, animated = TRUE, tooltip = NULL, threeD = 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 )
data |
a dataframe |
data2 |
|
category |
name of the column of |
stacks |
a list of stacks; a stack is a character vector of the form
|
seriesNames |
names of the series variables (the variables which appear
in the stacks), to appear in the legend; |
colors |
colors of the bars; |
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 in the cursor tooltips if
|
chartTitle |
chart title, it can be |
theme |
theme, |
animated |
Boolean, whether to animate the rendering of the graphic |
tooltip |
settings of the tooltips; |
threeD |
logical, whether to render the columns in 3D |
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 |
library(rAmCharts4) dat <- data.frame( year = c("2004", "2005", "2006"), europe = c(10, 15, 20), asia = c( 9, 10, 13), africa = c( 5, 6, 8), meast = c( 7, 8, 12), namerica = c(12, 15, 19), samerica = c(10, 16, 14) ) dat2 <- data.frame( year = c("2004", "2005", "2006"), europe = c( 7, 12, 16), asia = c( 8, 13, 10), africa = c( 7, 7, 10), meast = c( 8, 6, 14), namerica = c(10, 17, 17), samerica = c(12, 18, 17) ) stacks <- list( c("europe", "namerica"), c("asia", "africa", "meast", "samerica") ) seriesNames <- list( europe = "Europe", namerica = "North America", asia = "Asia", africa = "Africa", meast = "Middle East", samerica = "South America" ) amStackedBarChart( dat, data2 = dat2, category = "year", stacks = stacks, seriesNames = seriesNames, yLimits = c(0, 60), chartTitle = amText( "Stacked bar chart", fontFamily = "Trebuchet MS", fontSize = 30, fontWeight = "bold" ), xAxis = "Year", yAxis = "A quantity...", theme = "kelly", button = amButton("Update", position = 1), height = 450 )
library(rAmCharts4) dat <- data.frame( year = c("2004", "2005", "2006"), europe = c(10, 15, 20), asia = c( 9, 10, 13), africa = c( 5, 6, 8), meast = c( 7, 8, 12), namerica = c(12, 15, 19), samerica = c(10, 16, 14) ) dat2 <- data.frame( year = c("2004", "2005", "2006"), europe = c( 7, 12, 16), asia = c( 8, 13, 10), africa = c( 7, 7, 10), meast = c( 8, 6, 14), namerica = c(10, 17, 17), samerica = c(12, 18, 17) ) stacks <- list( c("europe", "namerica"), c("asia", "africa", "meast", "samerica") ) seriesNames <- list( europe = "Europe", namerica = "North America", asia = "Asia", africa = "Africa", meast = "Middle East", samerica = "South America" ) amStackedBarChart( dat, data2 = dat2, category = "year", stacks = stacks, seriesNames = seriesNames, yLimits = c(0, 60), chartTitle = amText( "Stacked bar chart", fontFamily = "Trebuchet MS", fontSize = 30, fontWeight = "bold" ), xAxis = "Year", yAxis = "A quantity...", theme = "kelly", button = amButton("Update", position = 1), height = 450 )
Create a list of settings for a text.
amText( text, color = NULL, fontSize = NULL, fontWeight = "normal", fontFamily = NULL )
amText( text, color = NULL, fontSize = NULL, fontWeight = "normal", fontFamily = NULL )
text |
the text to display, a character string |
color |
color of the text; it can be given by the name of a R color,
the name of a CSS color, e.g. |
fontSize |
size of the text |
fontWeight |
font weight of the text, it can be |
fontFamily |
font family |
A list of settings for a text.
There is no option for the font style; you can get an italicized
text by entering text = "[font-style:italic]Your text[/]"
.
Create list of settings for a tooltip.
amTooltip( text, textColor = NULL, textAlign = "middle", backgroundColor = NULL, backgroundOpacity = 0.6, borderColor = NULL, borderWidth = 2, pointerLength = 10, scale = 1, auto = FALSE )
amTooltip( text, textColor = NULL, textAlign = "middle", backgroundColor = NULL, backgroundOpacity = 0.6, borderColor = NULL, borderWidth = 2, pointerLength = 10, scale = 1, auto = FALSE )
text |
text to display in the tooltip; this should be a formatting string |
textColor |
text color |
textAlign |
alignement of the text, can be |
backgroundColor |
background color of the tooltip |
backgroundOpacity |
background opacity |
borderColor |
color of the border of the tooltip |
borderWidth |
width of the border of the tooltip |
pointerLength |
length of the pointer |
scale |
scale factor |
auto |
logical, whether to use automatic background color and text color |
A list of settings for a tooltip.
A color can be given by the name of a R color, the name of a CSS
color, e.g. "transparent"
or "fuchsia"
, an HEX code like
"#ff009a"
, a RGB code like "rgb(255,100,39)"
, or a HSL code
like "hsl(360,11,255)"
.
Zoom buttons.
amZoomButtons( halign = "left", valign = "top", marginH = 5, marginV = 5, zoomFactor = 0.1 )
amZoomButtons( halign = "left", valign = "top", marginH = 5, marginV = 5, zoomFactor = 0.1 )
halign |
|
valign |
|
marginH |
horizontal margin |
marginV |
vertical margin |
zoomFactor |
zoom factor |
A list of parameters for zoom buttons, for usage in
amLineChart
or amScatterChart
Adapters allow to have finer control of settings such as the colors of the columns of a bar chart or the colors of the points of a scatter chart.
amColorAdapterFromVector(colors) amColorAdapterFromCuts(cuts, colors, value)
amColorAdapterFromVector(colors) amColorAdapterFromCuts(cuts, colors, value)
colors |
a vector of colors |
cuts |
a vector of cut points (sorted increasingly) |
value |
a mathematical expression of the variables |
# bar chart with individual colors #### dat <- data.frame( country = c("USA", "China", "Japan", "Germany", "UK", "France"), visits = c(3025, 1882, 1809, 1322, 1122, 1114) ) amBarChart( data = dat, width = "600px", category = "country", values = "visits", showValues = FALSE, tooltip = FALSE, columnStyle = amColumn( color = amColorAdapterFromVector(hcl.colors(6, "Viridis")), opacity = 0.7, strokeColor = amColorAdapterFromVector(hcl.colors(6, "Cividis")), strokeWidth = 4 ), bullets = amCircle( color = amColorAdapterFromVector(hcl.colors(6, "Viridis")), opacity = 1, strokeColor = amColorAdapterFromVector(hcl.colors(6, "Cividis")), strokeWidth = 4, radius = 12 ), alwaysShowBullets = TRUE, chartTitle = amText(text = "Visits per country", fontSize = 22, color = "orangered"), backgroundColor = "rgb(164,167,174)", xAxis = list(title = amText(text = "Country", color = "maroon")), yAxis = list( title = amText(text = "Visits", color = "maroon"), gridLines = amLine(color = "white", width = 1, dash = "3,3") ), yLimits = c(0, 4000), valueFormatter = "#,###.", caption = amText(text = "Year 2018", color = "red") ) # usage example of amColorAdapterFromCuts #### set.seed(314159) dat <- data.frame( x = rnorm(200), y = rnorm(200) ) amScatterChart( data = dat, width = "500px", height = "500px", xValue = "x", yValues = "y", xLimits = c(-3,3), yLimits = c(-3,3), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = amCircle( color = amColorAdapterFromCuts( cuts = c(-2, -1, 1, 2), colors = c("red", "green", "blue", "green", "red"), value = "Y" ), opacity = 0.5, strokeColor = amColorAdapterFromCuts( cuts = c(-2, -1, 1, 2), colors = c("darkred", "darkgreen", "darkblue", "darkgreen", "darkred"), value = "Y" ) ), xAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), yAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), tooltip = FALSE, caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark") # other usage example of amColorAdapterFromCuts: linear gradient #### set.seed(314159) dat <- data.frame( x = rnorm(500), y = rnorm(500) ) amScatterChart( data = dat, width = "500px", height = "500px", xValue = "x", yValues = "y", xLimits = c(-3,3), yLimits = c(-3,3), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = amCircle( radius = 4, strokeWidth = 1, color = amColorAdapterFromCuts( cuts = seq(-3, 3, length.out = 121), colors = colorRampPalette( c("red","orangered","blue","white","blue","orangered","red") )(122), value = "X" ), opacity = 0.75, strokeColor = amColorAdapterFromCuts( cuts = seq(-3, 3, length.out = 121), colors = colorRampPalette( c("red","orangered","blue","white","blue","orangered","red") )(122), value = "X" ) ), xAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), yAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), tooltip = FALSE, caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark") # yet another usage example of amColorAdapterFromCuts: radial gradient set.seed(314159) dat <- data.frame( x = rnorm(1000), y = rnorm(1000) ) amScatterChart( data = dat, width = "500px", height = "500px", xValue = "x", yValues = "y", xLimits = c(-3,3), yLimits = c(-3,3), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = amCircle( radius = 4, strokeWidth = 1, color = amColorAdapterFromCuts( cuts = seq(0, 3, length.out = 121), colors = colorRampPalette( c("white","blue","orangered","red") )(122), value = "Math.sqrt(X**2+Y**2)" ), opacity = 0.75, strokeColor = amColorAdapterFromCuts( cuts = seq(0, 3, length.out = 121), colors = colorRampPalette( c("white","blue","orangered","red") )(122), value = "Math.sqrt(X**2+Y**2)" ) ), xAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), yAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), tooltip = FALSE, caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark")
# bar chart with individual colors #### dat <- data.frame( country = c("USA", "China", "Japan", "Germany", "UK", "France"), visits = c(3025, 1882, 1809, 1322, 1122, 1114) ) amBarChart( data = dat, width = "600px", category = "country", values = "visits", showValues = FALSE, tooltip = FALSE, columnStyle = amColumn( color = amColorAdapterFromVector(hcl.colors(6, "Viridis")), opacity = 0.7, strokeColor = amColorAdapterFromVector(hcl.colors(6, "Cividis")), strokeWidth = 4 ), bullets = amCircle( color = amColorAdapterFromVector(hcl.colors(6, "Viridis")), opacity = 1, strokeColor = amColorAdapterFromVector(hcl.colors(6, "Cividis")), strokeWidth = 4, radius = 12 ), alwaysShowBullets = TRUE, chartTitle = amText(text = "Visits per country", fontSize = 22, color = "orangered"), backgroundColor = "rgb(164,167,174)", xAxis = list(title = amText(text = "Country", color = "maroon")), yAxis = list( title = amText(text = "Visits", color = "maroon"), gridLines = amLine(color = "white", width = 1, dash = "3,3") ), yLimits = c(0, 4000), valueFormatter = "#,###.", caption = amText(text = "Year 2018", color = "red") ) # usage example of amColorAdapterFromCuts #### set.seed(314159) dat <- data.frame( x = rnorm(200), y = rnorm(200) ) amScatterChart( data = dat, width = "500px", height = "500px", xValue = "x", yValues = "y", xLimits = c(-3,3), yLimits = c(-3,3), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = amCircle( color = amColorAdapterFromCuts( cuts = c(-2, -1, 1, 2), colors = c("red", "green", "blue", "green", "red"), value = "Y" ), opacity = 0.5, strokeColor = amColorAdapterFromCuts( cuts = c(-2, -1, 1, 2), colors = c("darkred", "darkgreen", "darkblue", "darkgreen", "darkred"), value = "Y" ) ), xAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), yAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), tooltip = FALSE, caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark") # other usage example of amColorAdapterFromCuts: linear gradient #### set.seed(314159) dat <- data.frame( x = rnorm(500), y = rnorm(500) ) amScatterChart( data = dat, width = "500px", height = "500px", xValue = "x", yValues = "y", xLimits = c(-3,3), yLimits = c(-3,3), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = amCircle( radius = 4, strokeWidth = 1, color = amColorAdapterFromCuts( cuts = seq(-3, 3, length.out = 121), colors = colorRampPalette( c("red","orangered","blue","white","blue","orangered","red") )(122), value = "X" ), opacity = 0.75, strokeColor = amColorAdapterFromCuts( cuts = seq(-3, 3, length.out = 121), colors = colorRampPalette( c("red","orangered","blue","white","blue","orangered","red") )(122), value = "X" ) ), xAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), yAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), tooltip = FALSE, caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark") # yet another usage example of amColorAdapterFromCuts: radial gradient set.seed(314159) dat <- data.frame( x = rnorm(1000), y = rnorm(1000) ) amScatterChart( data = dat, width = "500px", height = "500px", xValue = "x", yValues = "y", xLimits = c(-3,3), yLimits = c(-3,3), draggable = FALSE, backgroundColor = "#30303d", pointsStyle = amCircle( radius = 4, strokeWidth = 1, color = amColorAdapterFromCuts( cuts = seq(0, 3, length.out = 121), colors = colorRampPalette( c("white","blue","orangered","red") )(122), value = "Math.sqrt(X**2+Y**2)" ), opacity = 0.75, strokeColor = amColorAdapterFromCuts( cuts = seq(0, 3, length.out = 121), colors = colorRampPalette( c("white","blue","orangered","red") )(122), value = "Math.sqrt(X**2+Y**2)" ) ), xAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), yAxis = list( breaks = amAxisBreaks(seq(-3, 3, by=1)), gridLines = amLine(opacity = 0.3, width = 1) ), tooltip = FALSE, caption = amText(text = "[font-style:italic]rAmCharts4[/]", color = "yellow"), theme = "dark")
These objects are imported from other packages.
Follow the links to their documentation:
JS
,
saveWidget
Create a list of settings for bullets, their shape and their style.
amTriangle( color = NULL, opacity = 1, width = 10, height = 10, strokeColor = NULL, strokeOpacity = 1, strokeWidth = 2, direction = "top", rotation = 0, image = NULL ) amCircle( color = NULL, opacity = 1, radius = 6, strokeColor = NULL, strokeOpacity = 1, strokeWidth = 2, image = NULL ) amRectangle( color = NULL, opacity = 1, width = 10, height = 10, strokeColor = NULL, strokeOpacity = 1, strokeWidth = 2, rotation = 0, cornerRadius = 3, image = NULL )
amTriangle( color = NULL, opacity = 1, width = 10, height = 10, strokeColor = NULL, strokeOpacity = 1, strokeWidth = 2, direction = "top", rotation = 0, image = NULL ) amCircle( color = NULL, opacity = 1, radius = 6, strokeColor = NULL, strokeOpacity = 1, strokeWidth = 2, image = NULL ) amRectangle( color = NULL, opacity = 1, width = 10, height = 10, strokeColor = NULL, strokeOpacity = 1, strokeWidth = 2, rotation = 0, cornerRadius = 3, image = NULL )
color |
bullet color; this can be a color adapter |
opacity |
bullet opacity, a number between 0 and 1 |
width |
bullet width |
height |
bullet height |
strokeColor |
stroke color of the bullet; this can be a color adapter |
strokeOpacity |
stroke opacity of the bullet, a number between 0 and 1 |
strokeWidth |
stroke width of the bullet |
direction |
triangle direction |
rotation |
rotation angle |
image |
option to include an image in the bullet, a list created
with |
radius |
circle radius |
cornerRadius |
radius of the rectangle corners |
A list of settings for the bullets.
A color can be given by the name of a R color, the name of a CSS
color, e.g. "transparent"
or "fuchsia"
, an HEX code like
"#ff009a"
, a RGB code like "rgb(255,100,39)"
, or a HSL code
like "hsl(360,11,255)"
.
rAmCharts4
in ShinyOutput and render functions for using the rAmCharts4
widgets within Shiny applications and interactive Rmd documents.
amChart4Output(outputId, width = "100%", height = "400px") renderAmChart4(expr, env = parent.frame(), quoted = FALSE)
amChart4Output(outputId, width = "100%", height = "400px") renderAmChart4(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
must be a valid CSS unit (like |
expr |
an expression that generates a chart with
|
env |
the environment in which to evaluate |
quoted |
whether |
library(rAmCharts4) library(shiny) library(lubridate) ui <- fluidPage( br(), fluidRow( column( width = 8, amChart4Output("linechart", height = "500px") ), column( width = 4, tags$fieldset( tags$legend("Chart data"), verbatimTextOutput("chartData"), ), tags$fieldset( tags$legend("Change"), verbatimTextOutput("chartChange") ) ) ) ) server <- function(input, output){ set.seed(666) dat <- data.frame( date = ymd(180101) + months(0:11), visits = rpois(12, 20), x = 1:12 ) output[["linechart"]] <- renderAmChart4({ amLineChart( data = dat, data2 = dat, xValue = "date", yValues = "visits", draggable = TRUE, chartTitle = amText( text = "Number of visits", color = "crimson", fontWeight = "bold", fontFamily = "cursive" ), xAxis = list( title = "Date", labels = amAxisLabels(rotation = -45), breaks = amAxisBreaks(timeInterval = "1 month") ), yAxis = "Visits", yLimits = c(0, 35), backgroundColor = "whitesmoke", tooltip = "[bold][font-style:italic]{dateX}[/]\nvisits: {valueY}[/]", Yformatter = "#", caption = amText( text = "[bold font-size:22]Year 2018[/]", color = "fuchsia" ), button = amButton( label = amText("Reset data", color = "black"), color = "seashell", position = 0.95 ), theme = "dataviz") }) output[["chartData"]] <- renderPrint({ input[["linechart"]] }) output[["chartChange"]] <- renderPrint({ input[["linechart_change"]] }) } if(interactive()) { shinyApp(ui, server) }
library(rAmCharts4) library(shiny) library(lubridate) ui <- fluidPage( br(), fluidRow( column( width = 8, amChart4Output("linechart", height = "500px") ), column( width = 4, tags$fieldset( tags$legend("Chart data"), verbatimTextOutput("chartData"), ), tags$fieldset( tags$legend("Change"), verbatimTextOutput("chartChange") ) ) ) ) server <- function(input, output){ set.seed(666) dat <- data.frame( date = ymd(180101) + months(0:11), visits = rpois(12, 20), x = 1:12 ) output[["linechart"]] <- renderAmChart4({ amLineChart( data = dat, data2 = dat, xValue = "date", yValues = "visits", draggable = TRUE, chartTitle = amText( text = "Number of visits", color = "crimson", fontWeight = "bold", fontFamily = "cursive" ), xAxis = list( title = "Date", labels = amAxisLabels(rotation = -45), breaks = amAxisBreaks(timeInterval = "1 month") ), yAxis = "Visits", yLimits = c(0, 35), backgroundColor = "whitesmoke", tooltip = "[bold][font-style:italic]{dateX}[/]\nvisits: {valueY}[/]", Yformatter = "#", caption = amText( text = "[bold font-size:22]Year 2018[/]", color = "fuchsia" ), button = amButton( label = amText("Reset data", color = "black"), color = "seashell", position = 0.95 ), theme = "dataviz") }) output[["chartData"]] <- renderPrint({ input[["linechart"]] }) output[["chartChange"]] <- renderPrint({ input[["linechart_change"]] }) } if(interactive()) { shinyApp(ui, server) }
Icons for usage in amImage
.
tinyIcon(icon, backgroundColor = NULL) tinyIcons() shinyAppTinyIcons()
tinyIcon(icon, backgroundColor = NULL) tinyIcons() shinyAppTinyIcons()
icon |
name of an icon; |
backgroundColor |
background color of the icon
(possibly |
A base64 string that can be used in the href
argument of
amImage
.
A color can be given by the name of a R color, the name of a CSS
color, e.g. "transparent"
or "fuchsia"
, an HEX code like
"#ff009a"
, a RGB code like "rgb(255,100,39)"
, or a HSL code
like "hsl(360,11,255)"
.
Update the data of a bar chart in a Shiny app (vertical, horizontal, radial, or stacked bar chart).
updateAmBarChart(session, outputId, data)
updateAmBarChart(session, outputId, data)
session |
the Shiny |
outputId |
the output id passed on to |
data |
new data; if it is not valid, then nothing will happen (in order
to be valid it must have the same structure as the data passed on to
|
library(rAmCharts4) library(shiny) ui <- fluidPage( br(), actionButton("update", "Update", class = "btn-primary"), br(), br(), amChart4Output("barchart", width = "650px", height = "470px") ) server <- function(input, output, session){ 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) ) newdat <- data.frame( country = c("USA", "China", "Japan", "Germany", "UK", "France"), income = rpois(6, 25), expenses = rpois(6, 20) ) output[["barchart"]] <- renderAmChart4({ amBarChart( data = dat, category = "country", values = c("income", "expenses"), valueNames = list(income = "Income", expenses = "Expenses"), draggable = TRUE, backgroundColor = "#30303d", columnStyle = list( income = amColumn( color = "darkmagenta", strokeColor = "#cccccc", strokeWidth = 2 ), expenses = amColumn( color = "darkred", strokeColor = "#cccccc", strokeWidth = 2 ) ), chartTitle = list(text = "Income and expenses per country"), xAxis = "Country", yAxis = "Income and expenses", yLimits = c(0, 41), valueFormatter = "#.#", caption = "Year 2018", theme = "dark") }) observeEvent(input[["update"]], { updateAmBarChart(session, "barchart", newdat) }) } if(interactive()){ shinyApp(ui, server) } # Survival probabilities #### library(shiny) library(rAmCharts4) probs <- c(control = 30, treatment = 75) # initial probabilities ui <- fluidPage( br(), sidebarLayout( sidebarPanel( wellPanel( tags$fieldset( tags$legend("Survival probability"), sliderInput( "control", "Control group", min = 0, max = 100, value = probs[["control"]], step = 1 ), sliderInput( "treatment", "Treatment group", min = 0, max = 100, value = probs[["treatment"]], step = 1 ) ) ) ), mainPanel( amChart4Output("barchart", width = "500px", height = "400px") ) ) ) server <- function(input, output, session){ dat <- data.frame( group = c("Control", "Treatment"), alive = c(probs[["control"]], probs[["treatment"]]), dead = 100 - c(probs[["control"]], probs[["treatment"]]) ) stacks <- list( c("alive", "dead") ) seriesNames <- list( alive = "Alive", dead = "Dead" ) output[["barchart"]] <- renderAmChart4({ amStackedBarChart( dat, category = "group", stacks = stacks, seriesNames = seriesNames, yLimits = c(0, 100), chartTitle = amText( "Survival probabilities", fontFamily = "Trebuchet MS", fontSize = 30, fontWeight = "bold" ), xAxis = "Group", yAxis = "Probability", theme = "dataviz" ) }) observeEvent(list(input[["control"]], input[["treatment"]]), { newdat <- data.frame( group = c("Control", "Treatment"), alive = c(input[["control"]], input[["treatment"]]), dead = 100 - c(input[["control"]], input[["treatment"]]) ) updateAmBarChart(session, "barchart", newdat) }) } if(interactive()){ shinyApp(ui, server) }
library(rAmCharts4) library(shiny) ui <- fluidPage( br(), actionButton("update", "Update", class = "btn-primary"), br(), br(), amChart4Output("barchart", width = "650px", height = "470px") ) server <- function(input, output, session){ 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) ) newdat <- data.frame( country = c("USA", "China", "Japan", "Germany", "UK", "France"), income = rpois(6, 25), expenses = rpois(6, 20) ) output[["barchart"]] <- renderAmChart4({ amBarChart( data = dat, category = "country", values = c("income", "expenses"), valueNames = list(income = "Income", expenses = "Expenses"), draggable = TRUE, backgroundColor = "#30303d", columnStyle = list( income = amColumn( color = "darkmagenta", strokeColor = "#cccccc", strokeWidth = 2 ), expenses = amColumn( color = "darkred", strokeColor = "#cccccc", strokeWidth = 2 ) ), chartTitle = list(text = "Income and expenses per country"), xAxis = "Country", yAxis = "Income and expenses", yLimits = c(0, 41), valueFormatter = "#.#", caption = "Year 2018", theme = "dark") }) observeEvent(input[["update"]], { updateAmBarChart(session, "barchart", newdat) }) } if(interactive()){ shinyApp(ui, server) } # Survival probabilities #### library(shiny) library(rAmCharts4) probs <- c(control = 30, treatment = 75) # initial probabilities ui <- fluidPage( br(), sidebarLayout( sidebarPanel( wellPanel( tags$fieldset( tags$legend("Survival probability"), sliderInput( "control", "Control group", min = 0, max = 100, value = probs[["control"]], step = 1 ), sliderInput( "treatment", "Treatment group", min = 0, max = 100, value = probs[["treatment"]], step = 1 ) ) ) ), mainPanel( amChart4Output("barchart", width = "500px", height = "400px") ) ) ) server <- function(input, output, session){ dat <- data.frame( group = c("Control", "Treatment"), alive = c(probs[["control"]], probs[["treatment"]]), dead = 100 - c(probs[["control"]], probs[["treatment"]]) ) stacks <- list( c("alive", "dead") ) seriesNames <- list( alive = "Alive", dead = "Dead" ) output[["barchart"]] <- renderAmChart4({ amStackedBarChart( dat, category = "group", stacks = stacks, seriesNames = seriesNames, yLimits = c(0, 100), chartTitle = amText( "Survival probabilities", fontFamily = "Trebuchet MS", fontSize = 30, fontWeight = "bold" ), xAxis = "Group", yAxis = "Probability", theme = "dataviz" ) }) observeEvent(list(input[["control"]], input[["treatment"]]), { newdat <- data.frame( group = c("Control", "Treatment"), alive = c(input[["control"]], input[["treatment"]]), dead = 100 - c(input[["control"]], input[["treatment"]]) ) updateAmBarChart(session, "barchart", newdat) }) } if(interactive()){ shinyApp(ui, server) }
Update the score of a gauge chart in a Shiny app
updateAmGaugeChart(session, outputId, score)
updateAmGaugeChart(session, outputId, score)
session |
the Shiny |
outputId |
the output id passed on to |
score |
new value of the score |
library(rAmCharts4) library(shiny) gradingData <- data.frame( label = c("Slow", "Moderate", "Fast"), lowScore = c(0, 100/3, 200/3), highScore = c(100/3, 200/3, 100) ) ui <- fluidPage( sidebarLayout( sidebarPanel( sliderInput( "slider", "Score", min = 0, max = 100, value = 30 ) ), mainPanel( amChart4Output("gauge", height = "500px") ) ) ) server <- function(input, output, session){ output[["gauge"]] <- renderAmChart4({ amGaugeChart( score = isolate(input[["slider"]]), minScore = 0, maxScore = 100, gradingData = gradingData, theme = "dataviz" ) }) observeEvent(input[["slider"]], { updateAmGaugeChart(session, "gauge", score = input[["slider"]]) }) } if(interactive()){ shinyApp(ui, server) }
library(rAmCharts4) library(shiny) gradingData <- data.frame( label = c("Slow", "Moderate", "Fast"), lowScore = c(0, 100/3, 200/3), highScore = c(100/3, 200/3, 100) ) ui <- fluidPage( sidebarLayout( sidebarPanel( sliderInput( "slider", "Score", min = 0, max = 100, value = 30 ) ), mainPanel( amChart4Output("gauge", height = "500px") ) ) ) server <- function(input, output, session){ output[["gauge"]] <- renderAmChart4({ amGaugeChart( score = isolate(input[["slider"]]), minScore = 0, maxScore = 100, gradingData = gradingData, theme = "dataviz" ) }) observeEvent(input[["slider"]], { updateAmGaugeChart(session, "gauge", score = input[["slider"]]) }) } if(interactive()){ shinyApp(ui, server) }
Update the data of a 100% staced bar chart in a Shiny app
(amPercentageBarChart
).
updateAmPercentageBarChart(session, outputId, data)
updateAmPercentageBarChart(session, outputId, data)
session |
the Shiny |
outputId |
the output id passed on to |
data |
new data; if it is not valid, then nothing will happen (in order
to be valid it must have the same structure as the data passed on to
|
library(rAmCharts4) library(shiny) dat <- data.frame( country = c("Australia", "Canada", "France", "Germany"), "35-44" = c(2, 2, 3, 3), "45-54" = c(9, 5, 7, 6), "55+" = c(8, 4, 6, 5), check.names = FALSE ) newdat <- data.frame( country = c("Australia", "Canada", "France", "Germany"), "35-44" = c(3, 2, 3, 4), "45-54" = c(7, 3, 5, 5), "55+" = c(7, 4, 5, 3), check.names = FALSE ) ui <- fluidPage( br(), actionButton("update", "Update", class = "btn-primary"), br(), br(), amChart4Output("pbarchart", width = "650px", height = "470px") ) server <- function(input, output, session){ output[["pbarchart"]] <- renderAmChart4({ amPercentageBarChart( dat, category = "country", values = c("35-44", "45-54", "55+"), chartTitle = "Profit by country and age breakdowns", xAxis = "Country", yAxis = "Profit", theme = "moonrisekingdom", legend = amLegend(position = "right") ) }) observeEvent(input[["update"]], { updateAmPercentageBarChart(session, "pbarchart", newdat) }) } if(interactive()){ shinyApp(ui, server) }
library(rAmCharts4) library(shiny) dat <- data.frame( country = c("Australia", "Canada", "France", "Germany"), "35-44" = c(2, 2, 3, 3), "45-54" = c(9, 5, 7, 6), "55+" = c(8, 4, 6, 5), check.names = FALSE ) newdat <- data.frame( country = c("Australia", "Canada", "France", "Germany"), "35-44" = c(3, 2, 3, 4), "45-54" = c(7, 3, 5, 5), "55+" = c(7, 4, 5, 3), check.names = FALSE ) ui <- fluidPage( br(), actionButton("update", "Update", class = "btn-primary"), br(), br(), amChart4Output("pbarchart", width = "650px", height = "470px") ) server <- function(input, output, session){ output[["pbarchart"]] <- renderAmChart4({ amPercentageBarChart( dat, category = "country", values = c("35-44", "45-54", "55+"), chartTitle = "Profit by country and age breakdowns", xAxis = "Country", yAxis = "Profit", theme = "moonrisekingdom", legend = amLegend(position = "right") ) }) observeEvent(input[["update"]], { updateAmPercentageBarChart(session, "pbarchart", newdat) }) } if(interactive()){ shinyApp(ui, server) }
Update the data of a pie chart in a Shiny app.
updateAmPieChart(session, outputId, data)
updateAmPieChart(session, outputId, data)
session |
the Shiny |
outputId |
the output id passed on to |
data |
new data; if it is not valid, then nothing will happen (in order
to be valid it must have the same structure as the data passed on to
|