# NOT RUN {
# 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")
# }
Run the code above in your browser using DataLab