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

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`
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
))

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers.

Here, although the code is complete, representative data is missing that would produce the same error message. It's hard to eyeball the code and guess which line is throwing the error, and, understandably, few are willing to expend the effort to reverse engineer the problem.

Can you construct a reprex to better help us to help you?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.