I have made an interactive plot with e-charts for r. The y-axis has negative values causing a horizontal x-axis to be drawn at zero. How can I move this line to the bottom (at the value of -100)? And, second how can I show all date values (preferably days) on the x-axis?
####################
# interactive plot #
####################
library(tidyverse)
library(lubridate)
library(echarts4r)
birthdate <- ymd("1980-04-20")
timeline <- seq(ymd(Sys.Date()-14), (ymd(Sys.Date() 14)), by = "days")
t <- as.numeric(timeline - birthdate)
physical <- sin(2*pi*t/23)*100
emotional <- sin(2*pi*t/28)*100
intellectual <- sin(2*pi*t/33)*100
df <- tibble(timeline,t, physical, emotional, intellectual)
df <- df |> pivot_longer(cols = c('physical', 'emotional', 'intellectual'),
names_to = 'biorhythms',
values_to = 'value')
df$biorhythms <- as.factor(df$biorhythms)
# view data tibble
df
# interactive plot
df |> dplyr::group_by(biorhythms) %>%
e_charts(x = timeline) |>
e_line(value) |>
e_format_y_axis(suffix = "%") |>
e_mark_line(data = list(xAxis = Sys.Date()), title = "Today", symbol = 'none') |>
e_title("Biorhythm Pseudo-Science") |>
e_tooltip() |>
e_theme("dark-digerati")
CodePudding user response:
Regarding your first question, just add e_x_axis(axisLine = list(onZero = FALSE)) |>
to your code:
# interactive plot
df |> dplyr::group_by(biorhythms) %>%
e_charts(x = timeline) |>
e_line(value) |>
e_x_axis(axisLine = list(onZero = FALSE)) |>
e_format_y_axis(suffix = "%") |>
e_mark_line(data = list(xAxis = Sys.Date()), title = "Today", symbol = 'none') |>
e_title("Biorhythm Pseudo-Science") |>
e_tooltip() |>
e_theme("dark-digerati")
Regarding your second question, aren't those numbers actually days? I think it is better to add a new issue for that one and try to show/explain what you want as an output. Thanks!