-1

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
  • 1
    As for your previous question, please provide a reproducible example fo your dataset by following this guide https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example, it will make easier to assist you. – dc37 Apr 17 '20 at 19:39
  • @dc37 but seriously why do you need data in this case? I mean if someone is experienced with R then he should definitely know how to give y axis a specific length. –  Apr 17 '20 at 19:48
  • 2
    Because it will depend of your dataset and its structure. Right now, your `y = nrow(IMDB)` mean you are passing a single value to your `ggplot`, the same for any x and fill values. It does not seem really informative for knowing what you are looking for. – dc37 Apr 17 '20 at 19:51
  • @dc37 country contains multiple values, year contains multiple values, that's all you need to know I believe to understand what I am asking for. Y axis need to be the number of rows of the entire data table. The table I have is too big I cant post it here either way. –  Apr 17 '20 at 19:59
  • 2
    From your last response to @dc37 you still seem to disregard his kind suggestion to take a look at how you can make a great reproducible example even in cases you have a very long dataset. Also, to your question why we need data or a reproducible example, it is because SO is a learning platform for everyone and a reproducible example will help others that may have the same issue with you in the future to understand how they can apply the solution to their case. Not because "someone experienced with R then he should definitely know how to give y axis a specific length". That's how we all learn. – Yach Apr 17 '20 at 20:06
  • @Yach how can data differ in fact? I mean everyone who are working with data frame in R have a table which contain some columns which contain some values. That's it! So, I mentioned I have countries and years as columns. What other values do you expect in a column that is called 'Countries' and the one called 'Years'? Do you expect that after I post the data set here the column Country will contain some Fruit names? –  Apr 17 '20 at 20:22
  • How many times have you happened to ask clarification questions when someone explains you something even if it sounds easy to someone else? How many times have you happened to take notes of something and then share them with someone else in a tidy and clear form? If you haven't never mind. If you have, then dedicating effort to help others with your question worths as much as the effort you put to ask for help yourself. Friendly and constructively. – Yach Apr 17 '20 at 21:06

1 Answers1

2

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 ?

dc37
  • 15,840
  • 4
  • 15
  • 32
  • exactly mate! You see you can help even without the data ;) –  Apr 17 '20 at 20:05
  • 2
    I will figure it out faster with data. Personally, it happens to me to not stop on a post when I do not see any reproducible data that I can try on my R session. To my opinion, it is also helpful not only to help you but also to help people visiting SO with an almost similar question. Maybe by seeing the structure of the data and the final graphic result, it can help us to figure it out if it is what they are looking for. Anyway, gald that this answer was what you are looking for. – dc37 Apr 17 '20 at 20:11