Vij
Vij

Reputation: 59

Why am I getting a error in my Time series plot?

Im working of this dataset - https://www.kaggle.com/dgomonov/new-york-city-airbnb-open-data

I am trying to plot number of reviews per day.

str(nycab$last_review) #since it is as charecter change to date
nycab$last_review <- lubridate::ymd(nycab$last_review)#change to date format

reviewsperday <- nycab %>%  #find number of reviews per day 
  group_by(nycab$last_review) %>%
  summarise(freq = n()) 

reviewsperday %>%
  plot_time_series(nycab$last_review, freq,  #plot time series 
                   .interactive = interactive,
                   .plotly_slider = TRUE )

However when I run the last piece of code it gives me this error

Error: Problem with `mutate()` input `.value_smooth`.
x `nm` must be `NULL` or a character vector the same length as `x`
i Input `.value_smooth` is `auto_smooth(...)`.

Which confuses me as I know the df is of equal length. Is this because I have NA's in my date column?

Upvotes: 0

Views: 714

Answers (2)

KM_83
KM_83

Reputation: 727

Looks like you found a solution, but it seems that removing NA is all you need.

reviewsperday %>% filter(!is.na(last_review)) %>%
  plot_time_series(last_review, freq,  #plot time series 
                   .interactive = FALSE,
                   .plotly_slider = TRUE )

Upvotes: 1

Vij
Vij

Reputation: 59

So the problem ended up being two fold. As there was NA's in the dataset and when you use group_by it changes the col back to character.

nycab <- na.omit(nycab)


reviewsperday <- nycab %>%  #find number of reviews per day 
  group_by(last_review) %>%
  summarise(freq = n()) 

reviewsperday$last_review <- lubridate::ymd(reviewsperday$last_review) #change to date format

reviewsperday %>%
  plot_time_series(last_review, freq,  #plot time series 
                   .plotly_slider = TRUE )

This should not give you an interactive time series graph

Upvotes: 0

Related Questions