These functions create various kinds of lines. They connect observations or create filled areas with customized border. Each layer may have one or several lines.
lc_line(
data = list(),
place = NULL,
...,
chartId = NULL,
layerId = NULL,
with = NULL,
addLayer = FALSE,
pacerStep = 50
)lc_path(
data = list(),
place = NULL,
...,
chartId = NULL,
layerId = NULL,
with = NULL,
addLayer = FALSE,
pacerStep = 50
)
lc_ribbon(
data = list(),
place = NULL,
...,
chartId = NULL,
layerId = NULL,
with = NULL,
addLayer = FALSE
)
lc_abLine(
data = list(),
place = NULL,
...,
chartId = NULL,
layerId = NULL,
with = NULL,
addLayer = FALSE,
pacerStep = 50
)
lc_hLine(
data = list(),
place = NULL,
...,
chartId = NULL,
layerId = NULL,
with = NULL,
addLayer = FALSE,
pacerStep = 50
)
lc_vLine(
data = list(),
place = NULL,
...,
chartId = NULL,
layerId = NULL,
with = NULL,
addLayer = FALSE,
pacerStep = 50
)
Name-value pairs of properties passed through the dat
function. These
properties will be re-evaluated on each updateCharts
call.
An ID of the container, where to place new chart. It will be ignored if the chart already exists. If not defined, the chart will be appended to the web page's body.
Name-value pairs of properties that will be evaluated only once and then will remain
constant. These properties can still be changed later using the setProperties
function.
An ID for the chart. All charts must have unique IDs. If a chart with the same ID already
exists, it will be replaced unless addLayer = TRUE
. If ID is not defined, it will be the same as the
value of the place
argument. And if both are not defined, the ID will be set to ChartN
,
where N - 1
is the number of existing charts.
An ID for the new layer. All layers within one chart must have different IDs. If a layer with the same
ID already exists, it will be replaced. If not defined, it will be set to LayerN
, where N - 1
is the current number of layers in this chart.
A dataset or a list from which other properties should be taken. If the dataset doesn't have a
column with the requested name, the variable will be searched for outside of the dataset. Must be
a data.frame
or a list
.
If there is already a chart with the same ID, this argument defines whether to replace it or to add a
new layer to it. This argument is ignored if both place
and chartId
are NULL
or if there is no
chart with the given ID.
Time in ms between two consecutive calls of an on_mouseover
event. Prevents over-queueing in case
of cumbersome computations. May be important when the chart works in canvas mode.
lc_line()
: connects points in the order of variables on the x axis.
lc_path()
: connects points in the order they are given.
lc_ribbon()
: displays a filled area, defined by ymax
and ymin
values.
lc_abLine()
: creates straight lines by intercept and slope values
lc_hLine()
: creates horizontal lines by y-intercept values
lc_vLine()
: creates vertical lines by x-intercept values
You can read more about different properties here.
x, y
- vector of x and y coordinates of the points to connect. Can be
vectors for a single line or m x n
matrix for n
lines.
ymax, ymin
- (only for lc_ribbon
) vectors of maximal and minimal values for a ribbon.
a, b
- (only for lc_abLine
) vectors of slope and intercept values respectively.
v
- (only for lc_vLine
) vector of x-intercepts.
h
- (only for lc_hLine
) vector of y-intercepts.
lineWidth
- (nor for lc_ribbon
) width of each line.
opacity
- a vector of opacity values for each line in the range from 0 to 1.
label
- vector of text labels for each line (labels by default are shown, when mouse hovers over a line).
dasharray
- defines pattern of dashes and gaps for each line.
informText
- text that appears when the mouse cursor moves over an element. Unlike label
,
completely overwrites the tooltip content with a custom HTML code. Must be a vector of characters (HTML code
for each element).
Colour settings
colour
- colour of the lines. Must be a colour name or a hexadecimal code. For
lc_ribbon
this property defines colour of the ribbon, not the strokes.
fill
- (not for lc_ribbon
) colour with which to fill area inside the line.
Must be a colour name or a hexadecimal code.
colourValue
- grouping values for different colours. Can be numbers or characters.
colourDomain
- a vector of all possible values for discrete colour scales
or a range of all possible colour values for the continuous ones.
palette
- a vector of colours to construct the colour scale.
colourLegendTitle
- a title for the colour legend.
addColourScaleToLegend
- whether or not to show the colour legend for the current layer.
globalColourScale
- whether or not to use one colour scale for all the layers.
stroke
- (only for lc_ribbon
) stroke colour for each ribbon.
Must be a colour name or a hexadecimal code.
strokeWidth
- (only for lc_ribbon
) width of the strokes for each ribbon.
Axes settings
logScaleX, logScaleY
- a base of logarithm for logarithmic scale transformation.
If 0 or FALSE
no transformation will be performed.
layerDomainX, layerDomainY
- default axes ranges for the given layer.
domainX, domainY
- default axes ranges for the entire chart. If not defined,
it is automatically set to include all layer domains.
contScaleX, contScaleY
- whether or not the axis should be continuous.
aspectRatio
- an aspect ratio for the chart.
axisTitleX, axisTitleY
- axis titles.
axisTitlePosX, axisTitlePosY
- positions of the axis titles. For each axis, one can specify a title position
across or along the corresponding axis. Possible options are "up"
(for title inside the plotting area)
or "down"
(outside the plotting area, under the axis), and
"start"
, "middle"
, "end"
. This property must be a string with one or two of the aforementioned options
(e.g. "middle down"
, "start"
, etc.).
ticksRotateX, ticksRotateY
- angles by which to rotate ticks (in degrees). Must be between
0 (horizontal ticks, default) and 90 (vertical ticks).
ticksX, ticksY
- sets of ticks for the axes.
Interactivity settings
on_click
- a function, to be called when one of the lines is clicked. Gets an
index of the clicked line as an argument.
on_clickPosition
- a function, to be called when any point of the chart is clicked. Unlike
on_click
, which is called only when an element of the chart (point, line, etc.) is clicked, this
function reacts to any click on the chart. As an argument, it receives a vector of x and y coordinates of
the click (based on the current axes scales). If one of the axes is categorical, the function will
get the closest tick to the clicked position.
on_mouseover
- a function, to be called when the mouse hovers over one of the lines.
Gets an index of the clicked line as an argument.
on_mouseout
- a function, to be called when the mouse moves out of one of the lines.
on_marked
- a function, to be called when any of the lines are selected (marked)
or deselected. Use getMarked
function to get the IDs of the currently marked lines. To mark lines,
select them with your mouse while holding the Shift key.
Legend settings
legend_width
- width of the legend in pixels. The default value is 200.
legend_height
- height of the legend in pixels. By default, it is equal to the height of the chart.
legend_sampleHeight
- height of a single key of the legend in pixels. The default value is 20.
legend_ncol
- number of columns to order several legends. By default, this is defined from the number
of legends to reach close to a square shape.
legend_container
- a DOM element of the web page where to place the legend. By default, the legend is
positioned to the right from the chart in a table cell specifically made for it. This should be a valid CSS selector.
If the specified element does not exist, the legend will be added to the web page's body.
\
Global chart settings
width
- width of the chart in pixels.
heigth
- height of the chart in pixels.
plotWidth
- width of the plotting area in pixels.
plotHeight
- height of the plotting area in pixels.
paddings
- padding sizes in pixels. Must be a list with all the following fields:
"top", "bottom", "left", "right"
.
title
- a title of the chart.
titleX, titleY
- coordinates of the chart title.
titleSize
- font-size of the chart title.
showLegend
- whether or not to show the legend.
showPanel
- whether of not to show the instrument panel (grey triangle in the upper-left corner of the chart).
transitionDuration
- duration of the transitions between any two states of the chart. If 0,
no animated transition is shown. It can be useful to turn the transition off, when lots of frequent
changes happen to the chart.
if (FALSE) x <- seq(0, 8, 0.2)
lc_line(dat(x = x, y = cbind(cos(x), sin(x)),
aspectRatio = 1,
colour = c("blue", "red"),
dasharray = c("5", "1 5 5")))
points <- seq(0, 6.5, 0.1)
x <- cos(points)
y <- sin(points)
lc_path(dat(x = sapply(0:2, function(i) x + i),
y = sapply(0:2, function(i) y + i),
fill = c("blue", "red", "black"),
opacity = c(0.3, 0.5, 0.7)))
x <- seq(0, 5, 0.1)
y <- x*3 + rnorm(length(x), sd = 2)
fit <- lm(y ~ x)
pred <- predict(fit, data.frame(x = x), se.fit = TRUE)
lc_ribbon(dat(ymin = pred$fit - 1.96 * pred$se.fit,
ymax = pred$fit + 1.96 * pred$se.fit,
x = x,
colour = "#555555"), chartId = "ribbonTest")
lc_scatter(dat(x = x, y = y), size = 2, chartId = "ribbonTest", addLayer = TRUE)
lc_abLine(dat(a = fit$coefficients[2], b = fit$coefficients[1]),
chartId = "ribbonTest", addLayer = TRUE)
lc_hLine(dat(h = seq(1, 9, 1), domainX = c(0, 10), domainY = c(0, 10)), chartId = "grid")
lc_vLine(dat(v = seq(1, 9, 1)), chartId = "grid", addLayer = TRUE)
Run the code above in your browser using DataLab