# --- Helper: convert NA to JS null ---
to_hc <- function(x) {
lapply(x, function(v) if (is.na(v)) NULL else v)
}
# --- Data ---
years <- as.character(2017:2023)
tv <- c(7.0, 6.0, 5.0, 4.5, 5.0, 5.1, 5.1)
films <- c(2.2, 1.8, 1.5, 1.1, 1.2, 1.19, 0.9)
music <- c(2.5, 1.8, 1.2, 0.8, 0.6, 0.55, 0.6)
pubs <- c(NA, NA, NA, NA, 2.6, 2.7, 2.7)
software <- c(NA, NA, NA, NA, 0.75, 0.85, 0.9)
sports <- c(NA, NA, NA, NA, 0.41, 0.75, 0.53)
total <- c(12.5, 10.5, 8.5, 7.0, 6.8, 6.8, 6.5)
# --- Build chart ---
highchart() |>
hc_chart(
type = "areaspline",
style = list(fontFamily = "system-ui, -apple-system, sans-serif"),
backgroundColor = "transparent"
) |>
hc_title(
text = "Εξέλιξη Ψηφιακής Πειρατείας ΕΕ-27",
style = list(fontSize = "16px", fontWeight = "700", color = "#1a1a2e")
) |>
hc_subtitle(
text = paste0(
"Μηνιαίες προσβάσεις ανά χρήστη ίντερνετ"
),
style = list(fontSize = "12px", color = "#888")
) |>
hc_xAxis(
categories = years,
labels = list(style = list(fontSize = "12px", color = "#666")),
plotBands = list(
list(
from = 2.7, to = 3.3,
color = "rgba(230,57,70,0.07)",
label = list(
text = "COVID-19",
style = list(fontSize = "10px", color = "#E63946",
fontWeight = "600"),
y = 18
)
)
),
plotLines = list(
list(
value = 3.5, color = "#457B9D", dashStyle = "Dash",
width = 1, zIndex = 3,
label = list(
text = "+3 κατηγορίες απο το 2021",
style = list(fontSize = "9px", color = "#457B9D",
fontWeight = "500"),
rotation = 0, y = -5, x = 5
)
)
)
) |>
hc_yAxis(
title = list(
text = "Προσβάσεις ανά χρήστη ανά μήνα",
style = list(fontSize = "11px", color = "#888")
),
min = 0,
gridLineColor = "#f0f0f0"
) |>
hc_tooltip(
shared = TRUE,
headerFormat = '<span style="font-size:13px;font-weight:600">{point.key}</span><br/>',
pointFormat = '<span style="color:{series.color}">\u25CF</span> {series.name}: <b>{point.y}</b><br/>',
backgroundColor = "rgba(255,255,255,0.97)",
borderColor = "#ddd",
borderRadius = 8
) |>
hc_plotOptions(
areaspline = list(
fillOpacity = 0.07,
lineWidth = 2.5,
marker = list(enabled = TRUE, radius = 4, symbol = "circle",
lineWidth = 2, lineColor = "#fff"),
connectNulls = FALSE
)
) |>
hc_legend(
layout = "horizontal", align = "center", verticalAlign = "bottom",
itemStyle = list(fontSize = "11px", fontWeight = "500", color = "#555")
) |>
# --- Solid series (full 2017-2023) ---
hc_add_series(name = "TV", data = tv,
color = "#457B9D", type = "areaspline") |>
hc_add_series(name = "Ταινίες", data = films,
color = "#E63946", type = "areaspline") |>
hc_add_series(name = "Μουσική", data = music,
color = "#2A9D8F", type = "areaspline") |>
# --- Dashed series (2021+ only, NAs → JS null) ---
hc_add_series(name = "Εκδόσεις", data = to_hc(pubs),
color = "#E9C46A", type = "areaspline",
dashStyle = "ShortDash") |>
hc_add_series(name = "Λογισμικό", data = to_hc(software),
color = "#264653", type = "areaspline",
dashStyle = "ShortDash") |>
hc_add_series(name = "Αθλητικά Live", data = to_hc(sports),
color = "#E76F51", type = "areaspline",
dashStyle = "ShortDot") |>
# --- Total line (bold, no fill) ---
hc_add_series(name = "Σύνολο (TV + Ταινίες + Μουσική)", data = total,
color = "#1a1a2e", type = "spline",
lineWidth = 3, zIndex = 10,
marker = list(radius = 5, fillColor = "#1a1a2e",
lineColor = "#fff", lineWidth = 2))