Search code examples
rggplot2bar-chartstacked-chart

How to give y axis the total number of rows of a table in ggplot stacked bar?


I am using GGPLOT to create a stacked bar chart where y axis should be total number of movies, x axis should be year and the fill should be countries.

Here what I have tried so far but Y axis is giving a irregular number:

ggplot(IMDB, aes(fill=country,y=nrow(IMDB), x=year)) 
 + geom_bar(position="stack", stat="identity")

Table sample:

year   country
2002   Germany
1998   USA
1955   Italy

Solution

  • Maybe try:

    ggplot(IMDB, aes(fill=country, x=year)) 
     + geom_bar(position="stack")
    

    geom_bar will give the count of movies per year per country.

    Is it what you are looking for ?