Learn R Programming

highcharter (version 0.7.0)

hc_add_series_scatter: Shortcut for create scatter plots

Description

This function helps to create scatter plot from two numerics vectors. Options arguments like size, color and label for points are added.

Usage

hc_add_series_scatter(hc, x, y, z = NULL, color = NULL, label = NULL,
  showInLegend = FALSE, ...)

Arguments

hc

A highchart htmlwidget object.

x

A numeric vector.

y

A numeric vector. Same length of x.

z

A numeric vector for size. Same length of x.

color

A vector to color the points.

label

A vector to put names in the dots if you enable the datalabels.

showInLegend

Logical value to show or not the data in the legend box.

...

Additional shared arguments for the data series (http://api.highcharts.com/highcharts#series).

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
hc <- highchart()

hc_add_series_scatter(hc, mtcars$wt, mtcars$mpg)
hc_add_series_scatter(hc, mtcars$wt, mtcars$mpg, mtcars$drat)
hc_add_series_scatter(hc, mtcars$wt, mtcars$mpg, mtcars$drat, mtcars$am)
hc_add_series_scatter(hc, mtcars$wt, mtcars$mpg, mtcars$drat, mtcars$qsec)
hc_add_series_scatter(hc, mtcars$wt, mtcars$mpg, mtcars$drat, mtcars$qsec, rownames(mtcars))

# Add named attributes to data (attributes length needs to match number of rows)
hc_add_series_scatter(hc, mtcars$wt, mtcars$mpg, mtcars$drat, mtcars$qsec,
                      name = rownames(mtcars), gear = mtcars$gear) %>%
  hc_tooltip(pointFormat = "<b>{point.name}</b><br/>Gear: {point.gear}")
  
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab