amLineChart {rAmCharts4} | R Documentation |
HTML widget displaying a line chart
Description
Create a HTML widget displaying a line chart.
Usage
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
)
Arguments
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 |
Examples
# 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")