Created
May 17, 2021 20:03
-
-
Save RamiKrispin/f91d53d1d6b5c92814df676f12cacbb7 to your computer and use it in GitHub Desktop.
example for two y axis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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