I am having issues creating a barplot with unique value

Hello All,

Please I am trying to plot genres against count, but I am having issues with the multiple variables in the genres column.
Netflix_1 <- read_csv("titles.csv")
Netflix _1
Genres <- Netflix_1 %>% ggplot(aes(x=reorder(genres, genres, function(x)-length(x)),fill=genres))+
geom_text(stat="count",aes(label= ..count..),vjust=-1)+
labs(title ="count plot",y="", x="Genres").

I need to achieve something like this;

This is not very clear. Can you give sample data or explain more what your requirements are.

@kuttan98 , this is the link to the dataset 📉EDA on Netflix Movies and TV Shows🍟 | Kaggle
I used the title.csv files though.
There is a particular column(genres) consisting of multiple variables, and I want to plot a barchart of the individual variables.

Ok I have not looked the data. But my expectation is that it will be as how I have given below as reprex.
Check this code.
Hope it helps,



data %>% 
  geom_bar(width = .5)+
  labs(title = "Count of Genre movies",
       y="Number of Movies")

Thanks you @kuttan98 , The dataset consist of different columns and I am interested in working with a particular column called genre. However, this column comes like ["drama", "crime","romance"] in a row, how do I go about plotting a barplot with it? Please kindly check out dataset.

I checked the link. I am unable to find the data. Can you just send a reprex with a sample data. You can check this link to find out how to give a reprex.


structure(list(id = c("ts300399", "tm84618", "tm154986", "tm127384", 
"tm120801", "ts22164", "tm70993", "tm14873", "tm119281", "tm98978"
), title = c("Five Came Back: The Reference Films", "Taxi Driver", 
"Deliverance", "Monty Python and the Holy Grail", "The Dirty Dozen", 
"Monty Python's Flying Circus", "Life of Brian", "Dirty Harry", 
"Bonnie and Clyde", "The Blue Lagoon"), type = c("SHOW", "MOVIE", 
"MOVIE"), description = c("This collection includes 12 World War II-era propaganda films — many of which are graphic and offensive — discussed in the docuseries \"Five Came Back.\"", 
"A mentally unstable Vietnam War veteran works as a night-time taxi driver in New York City where the perceived decadence and sleaze feed his urge for violent action.", 
"Intent on seeing the Cahulawassee River before it's turned into one huge lake, outdoor fanatic Lewis Medlock takes his friends on a river-rafting trip they'll never forget into the dangerous American back-country.", 
"King Arthur, accompanied by his squire, recruits his Knights of the Round Table, including Sir Bedevere the Wise, Sir Lancelot the Brave, Sir Robin the Not-Quite-So-Brave-As-Sir-Lancelot and Sir Galahad the Pure. On the way, Arthur battles the Black Knight who, despite having had all his limbs chopped off, insists he can still fight. They reach Camelot, but Arthur decides not  to enter, as \"it is a silly place\".", 
"12 American military prisoners in World War II are ordered to infiltrate a well-guarded enemy château and kill the Nazi officers vacationing there. The soldiers, most of whom are facing death sentences for a variety of violent crimes, agree to the mission and the possible commuting of their sentences.", 
"A British sketch comedy series with the shows being composed of surreality, risqué or innuendo-laden humour, sight gags and observational sketches without punchlines.", 
"Brian Cohen is an average young Jewish man, but through a series of ridiculous events, he gains a reputation as the Messiah. When he's not dodging his followers or being scolded by his shrill mother, the hapless Brian has to contend with the pompous Pontius Pilate and acronym-obsessed members of a separatist movement. Rife with Monty Python's signature absurdity, the tale finds Brian's life paralleling Biblical lore, albeit with many more laughs.", 
"When a madman dubbed 'Scorpio' terrorizes San Francisco, hard-nosed cop, Harry Callahan – famous for his take-no-prisoners approach to law enforcement – is tasked with hunting down the psychopath. Harry eventually collars Scorpio in the process of rescuing a kidnap victim, only to see him walk on technicalities. Now, the maverick detective is determined to nail the maniac himself.", 
"In the 1930s, bored waitress Bonnie Parker falls in love with an ex-con named Clyde Barrow and together they start a violent crime spree through the country, stealing cars and robbing banks.", 
"Two small children and a ship's cook survive a shipwreck and find safety on an idyllic tropical island. Soon, however, the cook dies and the young boy and girl are left on their own. Days become years and Emmeline and Richard make a home for themselves surrounded by exotic creatures and nature's beauty. But will they ever see civilization again?"
), release_year = c(1945, 1976, 1972, 1975, 1967, 1969, 1979, 
1971, 1967, 1980), age_certification = c("TV-MA", "R", "R", "PG", 
NA, "TV-14", "R", "R", "R", "R"), runtime = c(51, 114, 109, 91, 
150, 30, 94, 102, 110, 104), genres = c("['documentation']", 
"['drama', 'crime']", "['drama', 'action', 'thriller', 'european']", 
"['fantasy', 'action', 'comedy']", "['war', 'action']", "['comedy', 'european']", 
"['comedy']", "['thriller', 'action', 'crime']", "['crime', 'drama', 'action']", 
"['romance', 'action', 'drama']"), production_countries = c("['US']", 
"['US']", "['US']", "['GB']", "['GB', 'US']", "['GB']", "['GB']", 
"['US']", "['US']", "['US']"), seasons = c(1, NA, NA, NA, NA, 
4, NA, NA, NA, NA), imdb_id = c(NA, "tt0075314", "tt0068473", 
"tt0071853", "tt0061578", "tt0063929", "tt0079470", "tt0066999", 
"tt0061418", "tt0080453"), imdb_score = c(NA, 8.2, 7.7, 8.2, 
7.7, 8.8, 8, 7.7, 7.7, 5.8), imdb_votes = c(NA, 808582, 107673, 
534486, 72662, 73424, 395024, 155051, 112048, 69844), tmdb_popularity = c(0.6, 
40.965, 10.01, 15.461, 20.398, 17.617, 17.77, 12.817, 15.687, 
50.324), tmdb_score = c(NA, 8.179, 7.3, 7.811, 7.6, 8.306, 7.8, 
7.5, 7.5, 6.156)), row.names = c(NA, -10L), class = c("tbl_df", 
"tbl", "data.frame"))



net <- net %>% 
  mutate(genres = gsub("\\[", "", genres),
         genres = gsub("\\]", "", genres),
         genres = str_replace_all(genres, "'", ""),
         genres = str_replace_all(genres, " ", "")) %>% 
  separate(genres, into = c("A", "B", "C", "D", "E", "F", "G", "H")) %>% 
  pivot_longer(c("A", "B", "C", "D", "E", "F", "G", "H")) %>% 
  select(-name) %>% 

net %>% 
  count(value) %>%
  mutate(value = factor(value),
         value = fct_reorder(value, -n)) %>% 
  ggplot(aes(x = value, y = n)) +

Can it be a good starting point?

1 Like

Sure, it did! Thanks so much

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.