Hi,
I have several charts tracking various daily COVID-19 metrics overt time. When we crossed into January 2021, both the bar and line chart put the new data before March 2020 despite the it being formatted as a date. I added:
type = "date",
range = c('2020-03-01','2021-01-31'),
title = ""),
![Screen Shot 2021-01-04 at 5.36.42 PM|686x500](upload://iPUcIL7dUFdoFkBwUY5qzhfGHgi.png)
This solved that issue, but I can't figure out how to fix the line graph.
totaldeaths <- plot_ly(death) %>%
add_trace(x = ~Date,
y = ~`NEW DEATHS`,
type = 'bar',
name = 'Daily deaths',
marker = list(color = '#969696'),
hoverinfo = "text",
text = ~paste('Daily deaths<br>', `NEW DEATHS`)) %>%
add_trace(x = ~Date,
y = ~`SEVEN DAY DEATH`,
type = 'scatter',
mode = 'lines', name = '7-day avg.', yaxis = 'y2',
line = list(color = '#a50f15'),
hoverinfo = "text",
hovertemplate = '7-day avg.<br> %{y:,}<extra></extra>') %>%
layout(title = 'Pa. COVID-19 deaths',
legend = list(orientation = 'h', y=1, x=0.5,xanchor = "center"),
margin = list (r="70"),
xaxis = list(
type = "date",
range = c('2020-03-01','2021-01-31'),
title = ""),
yaxis = list(side = 'left',
title = 'New deaths', showgrid = FALSE, zeroline = FALSE,
range =c(0,500)),
yaxis2 = list(
side = 'right',
overlaying = "y", title = '7-day avg.',
showgrid = FALSE, zeroline = FALSE,
range = c(0,500)),
annotations =
list(x = 1, y = -0.1, text = "Source: Pa. DOH. Note state removed 201 probable deaths 4/23",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=0,
font=list(size=10, color="black")))
Thanks,
Sara