Skip to contents

Draw an interactive scatterplot or line plot using 'Chart.js'.

Usage

# Default S3 method
plotjs(
  x,
  y,
  type = "p",
  xlim = NULL,
  ylim = NULL,
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  zoom = TRUE,
  col.group = NULL,
  col = NULL,
  legend.title = NULL,
  legend.position = "right",
  sci.x = FALSE,
  sci.y = FALSE,
  ...
)

Arguments

x

the x coordinates for the plot.

y

the y coordinates for the plot.

type

1-character string giving the type of plot desired. The following values are possible: "p" for points, "l" for lines, and "b" for both points and lines.

xlim

the x limits (x1, x2) of the plot.

ylim

the y limits of the plot.

main

a main title for the plot.

xlab

a label for the x axis, defaults to a description of x.

ylab

a label for the y axis, defaults to a description of y.

zoom

logical; should the zooming feature be enabled for the plot?

col.group

optionally, a factor the same length as x by which to group and color points.

col

The colors for the lines and points. If col.group is specified, this can be a vector of colors to use for each group in the data. If NULL, Chart.js default colors are used.

legend.title

a title for the legend. Defaults to a description of col.group if not set. You can also use legend.title = FALSE to suppress the legend title.

legend.position

Position of the plot legend. Possible values are "right", "bottom", "inset", and "hide". This is ignored if all points are colored the same.

sci.x

logical indicating whether scientific notation should be used for the x-axis.

sci.y

logical indicating whether scientific notation should be used for the y-axis.

...

arguments passed to htmlwidgets::createWidget(): width, height, and elementId. These arguments default to NULL.

Examples

data(mtcars)
plotjs(mtcars$hp, mtcars$qsec)
plotjs(mtcars$disp, mtcars$hp, main = "Displacement vs. HP in mtcars")