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