The data I'm trying to visualize has two assessments performed on the same time scale, but at different intervals (i.e. Temperature taken 4 times over 12 hours, pain assessed every hour), as an example:
df <- data.frame(
Hour = 0:12,
Pain = sample(7:10, 13, TRUE),
Temp = c(36.8,rep(NA,3),37.2,rep(NA,3),37.4,rep(NA,3),37.0)
)
In ggplot, I'd visualize it like this:
library(ggplot2)
ggplot(df) +
geom_col(aes(x = Hour, y = Pain)) +
geom_point(aes(x = Hour, y = Temp/3)) +
geom_line(data = df[!is.na(df$Temp), ], aes(x = Hour, y = Temp/3)) +
scale_y_continuous(sec.axis = sec_axis(~.*3,name = "Temp"))
In echarts4r however, I cannot get my line to be continuous (I believe because of the NA values)
library(echarts4r)
e_chart(df, Hour) |> e_bar(Pain) |> e_line(Temp)
Is there a way to subset the dataset before e_line to remove the missing values - I've searched online and can't seem to find anything? Or should I be structuring my data differently?