Skip to content

Instantly share code, notes, and snippets.

@RamiKrispin
Created May 17, 2021 20:03
Show Gist options
  • Select an option

  • Save RamiKrispin/f91d53d1d6b5c92814df676f12cacbb7 to your computer and use it in GitHub Desktop.

Select an option

Save RamiKrispin/f91d53d1d6b5c92814df676f12cacbb7 to your computer and use it in GitHub Desktop.
example for two y axis
library(coronavirus)
library(dplyr)
raw <- refresh_coronavirus_jhu()
head(raw)
df <- raw %>%
filter(location == "Israel",
data_type == "cases_new") %>%
select(date, new_cases = value) %>%
arrange(date)
head(df)
plot(df$date, df$new_cases, type = "l")
p <- plot_ly() %>%
add_segments(y = 0.203,
yend = 0.203,
x = min(df$date),
xend = max(df$date),
name = "control",
yaxis = "y2",
line = list(color = "black", dash = "dash")) %>%
add_segments(y = 0.207,
yend = 0.207,
x = min(df$date),
xend = max(df$date),
name = "treatment 1",
yaxis = "y2",
line = list(color = "black", dash = "dot")) %>%
add_segments(y = 0.198,
yend = 0.198,
x = min(df$date),
xend = max(df$date),
name = "treatment 2",
yaxis = "y2") %>%
add_lines(x = df$date,
y = df$new_cases,
name = "Daily New Cases") %>%
layout(
title = "Your title",
yaxis2 = list(
range = c(0.19, 0.21),
tickfont = list(color = "green",
family = "Arieal"),
overlaying = "y",
side = "right",
title = "Regression Coefficent"
),
xaxis = list(title="Weekly Index")
)
p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment