I have converted the basic ggplot
into plotly
graph but unable to move legend title
.
- Basic ggplot:
cases_ts_India <- df_stack %>%
filter(Country.Region == "India") %>%
ggplot(aes(x = Date, y = Cases_count, col = Cases_type)) +
geom_path()
cases_ts_India
- plotly graph:
- Moved the
legend
but unable to movelegend title
and its showing starting part of the title at the old location:
ggplotly(cases_ts_India) %>%
layout(legend = list(orientation = "h", y =-0.2))
I have tried moving title but it didn't work with below lines of code:
ggplotly(cases_ts_India) %>%
layout(legend = list(orientation = "h", x =0.2, y = -0.2),
legend.title = list(orientation = "h", x =0.2, y = -0.2))
Updating Attempt:
cases_ts_India <- cases_ts_India +
theme( legend.title = element_blank())
ggplotly(cases_ts_India) %>%
layout(title = "India Cases types over the year ",
legend = list(orientation = "h", x =0.2, y = -0.2)) %>%
add_annotations( text="Cases_type",
x=0.1, xanchor="left",
y=-0.2, yanchor="bottom", # Same y as legend below
legendtitle=TRUE, showarrow=FALSE )