I want to plot multiple lines in the same chart. Each line represent an age group (grupo_edad). In the x axis is the week when the cases are notified (epiweek) and the y axis is the incidence rate (inc).
These is my data:
inc_015
When I use plotly the result is perfect:
p <- plot_ly()%>%
layout(title = "Curvas de tasas de incidencia de casos notificados de COVID-19 \n en la Región Metropolitana, según grupo etario y semana epidemiológica primeros síntomas",
xaxis = list(title = "Semana Epidemiológica"),
yaxis = list (title = "Tasa x 100.000 habitantes") ) %>%
add_trace(x = inc_015$epiweek, y = inc_015$inc, type = 'scatter', mode = 'line', name = '0 a 15',
line=list(color='#16e3ff',dash='dashed')) %>%
add_trace(x = inc_1525$epiweek, y = inc_1525$inc, type = 'scatter', mode = 'line', name = '15 a 25',
line=list(color='#00c9e4',dash='dashed'))
p
But when I try with ggplot the result is totally different, the points are connected vertically
ggplot(data=incidencia1,
aes(x=epiweek, y=inc, colour=grupo_edad)) +
geom_point()
Can someone tell me how to display the same graph that I made with plotly in ggplot2?
geom_point()
shouldn't be connecting points at all.geom_line()
connects them in order of X.geom_path()
connects them in order of appearance in the dataframe. Besides that, your ggplot2 code looks correct and should work as intended. – cymondput()
would have been very useful. Or in this case, the data looks like public covid data, so a link to the source would be the simplest option. – cymon