0

https://www.kaggle.com/shivamb/netflix-shows-and-movies-exploratory-analysis/notebook contains the data set. (File size - 2.13 MB).

I am trying to plot the top twenty category of contents that are provided by Netflix.

The code that I have tried is as follows,

library(tidyverse)
library(lubridate)    

net_flix <- read.csv("netflix_titles_nov_2019.csv")

net_flix %>% separate_rows(listed_in, sep = ",")%>%
    count(listed_in)%>%
    slice_max(n, n = 20)%>%
    ggplot(aes(y = fct_reorder(listed_in, n), x = n))+
    geom_col()

The resultant output is as follows, [Top 20 categories of shows on Netflix]

As it can be seen from the graph that there are a lot categories like Dramas, Comedies, International TV Shows are appearing in multiple positions.

The expected output is as follows:

enter image description here

1
  • Can you give a hint on how the data looks like after slice_max? Or in general, how it looks like? This would help (you) a lot. Commented Jun 10, 2020 at 14:40

1 Answer 1

1

welcome to SO, I think you messed up your strings with spaces, also try to follow the ggplot convention on the grammar of graphics

library(tidyverse)
library(lubridate)

net_flix <- read_csv("netflix_titles.csv")

net_flix %>%
  separate_rows(listed_in, sep = ",") %>%
  mutate(listed_in = listed_in %>% str_squish()) %>%
  count(listed_in) %>%
  top_n(20, wt = n) %>%
  ggplot(aes(x = fct_reorder(listed_in, n), y = n)) +
  geom_col() +
  coord_flip()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It worked. str_squish() function is something new that I learnt today.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.