I have a dataset with two variables: 1) Country; 2) Coalition government or not over time (binary).
I want to use ggplot to plot a bar plot in which I have country on the X-axis and the percentage of years in which the country had a coalition government (Y=1). Each of the countries should sum to 100 pct. leading to them having the same size.
It is basically the same plot which is asked for in this question (Create stacked barplot where each stack is scaled to sum to 100%), except that I have only two outcomes (coalition government or not) and not five.
Although I follow the instructions in the answer to the question, I get the attached unsuccesful plot, using this code:
ggplot(data,aes(x = countryname, y = alliance,fill = alliance)) +
geom_bar(position = "fill",stat = "identity") +
scale_y_discrete(labels = percent_format())
I don't know what I am doing wrong, and I have tried so many different things now. Can anyone help me?