Нужно добавить линию, параллельную оси X, на график, построенный с помощью пакета highcharter
.
2 ответа
Используется параметр plotLines
функции hc_xAxis
или hc_yAxis
. Поддерживаются следующие параметры: label
(аннотация), color
(цвет), width
(толщина линии), value
(координата оси). См. также документацию highcharts (https://api.highcharts.com/highcharts/xAxis.plotLines).
Пример описан в документации к пакету highcharter: http://jkunst.com/highcharter/highcharts-api.html
library(highcharter)
data(diamonds, mpg, package = "ggplot2")
hchart(mpg, "scatter", hcaes(x = displ, y = hwy, group = class)) %>%
hc_xAxis(title = list(text = "Month in x Axis"),
opposite = TRUE,
plotLines = list(
list(label = list(text = "This is a plotLine"),
color = "#FF0000",
width = 2,
value = 2),
list(label = list(text = "This is a plotLine"),
color = "#FF0000",
width = 2,
value = 6))) %>%
hc_yAxis(title = list(text = "Temperature in y Axis"),
opposite = TRUE,
minorTickInterval = "auto",
minorGridLineDashStyle = "LongDashDotDot",
showFirstLabel = FALSE,
showLastLabel = FALSE,
plotLines = list(
list(label = list(text = "This is a plotBand"),
color = "#FF0000",
width = 2,
value = 30)))
Добавить линию на график:
Используем функцию plotlines в атрибутах xAxis or yAxis. Значение через 2 list ()
xAxis( ... Plotlines = list ( list ( ... ) )