tidyverse/design

R Programming-Error: Tibble columns must have consistent lengths, only values of length one are recycled: * Length 61: Column `y` * Length 10358: Column `x`

BenRoshan100 opened this issue · 1 comments

I am trying to plot the coronavirus spread in India vs Rest of the world by using the below R code
I have corona_world as a dataframe and created daily_confirmed dataframe from it .I have eliminated all values of NA in variable column 'India' . But still the error says it does not have same length. I don't understand why it isn't working. Please help

Error: Tibble columns must have consistent lengths, only values of length one are recycled: * Length 61: Column y * Length 10358: Column x
err
err1

daily_confirmed <- corona_world %>%
dplyr::select(Confirmed) %>%
dplyr::mutate(country = dplyr::if_else(corona_world$Country.Region == "India",
"India",
"Rest of the World")) %>%
dplyr::group_by(corona_world$ObservationDate, country) %>%
dplyr::summarise(total = sum(Confirmed, rm.na=TRUE)) %>%
dplyr::ungroup() %>%
tidyr::pivot_wider(names_from = country, values_from = total)

daily_confirmed <- daily_confirmed[-c(1:8),]
daily_confirmed %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~ corona_world$ObservationDate,
y = ~ India,
type = "scatter",
mode = "lines+markers",
name = "India") %>%
plotly::add_trace(x = ~ corona_world$ObservationDate,
y = ~ Rest of the World,
type = "scatter",
mode = "lines+markers",
name = "Rest of the World") %>%
plotly::layout(title = "",
legend = list(x = 0.1, y = 0.9),
yaxis = list(title = "Number of New Cases"),
xaxis = list(title = "Date"),
hovermode = "compare",
margin = list(
b = 10,
t = 10,
pad = 2
))

This sort of question is a better fit for https://community.rstudio.com. Do you mind asking it over there? (You might want to read https://www.tidyverse.org/help/ first to maximise your chances of getting a good answer)