Golem
Golem

Reputation: 126

How to plot two different data sets of same column using echarts4r?

I have sample data for two datasets:

one <- data.frame(
  Timestamp = seq(from = as.POSIXct("2023-07-01"), by = "days", length.out = 5),
  `Heat Capacity` = c(10, 15, 8, 12, 20)
)


two <- data.frame(
  Timestamp = seq(from = as.POSIXct("2023-07-01"), by = "days", length.out = 3),
  `Heat Capacity` = c(8, 12, 6)
)

Without combining the two dataframes, can a line chart be formed using echarts4r?

I have done it using ggplot:

one_graph <- ggplot() +
  geom_line(data = one, aes(x = one[[1]], y = one[[2]])) +
  geom_line(data = two, aes(x = two[[1]], y = two[[2]])) 

Can the same be achieved using echarts4r?

Upvotes: 0

Views: 220

Answers (1)

Jan
Jan

Reputation: 9348

This is possible:

library(echarts4r)

one |> e_charts(Timestamp) |> 
    e_line(serie = Heat.Capacity) |> 
    e_data(data = two) |> 
    e_line(serie = Heat.Capacity)

enter image description here

Upvotes: 2

Related Questions