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