Hello. Trying to work with this df to make a stacked barplot
party <- data.frame(
stringsAsFactors = FALSE,
party_name = c("Ex-Left","Ex-Left","Ex-Left",
"Ex-Left","Ex-Left","Ex-Left","Ex-Left","Ex-Left",
"Ex-Left","Ex-Left","Ex-Left","Left","Left","Left",
"Left","Left","Left","Left","Left","Left","Left",
"Left","Conservative","Conservative","Right National",
"Right National","Right National","Right National",
"Right National","Right National","Right National",
"Right National","Right National","Liberal","Liberal",
"Liberal","Liberal","Liberal","Liberal","Liberal",
"FarRight","FarRight","FarRight","FarRight","FarRight",
"FarRight","FarRight","FarRight","FarRight","FarRight",
"FarRight"),
value = c(924,1.209,1.321,2.398,1.45,
1.477,1.749,1.7,2.552,773,2.552,2.307,16.647,
12.514,10.542,11.226,9.766,12.058,10.426,8.444,6.766,
10.407,2.522,6.013,2.989,2.896,3.493,2.39,2.471,
1.671,1.713,1.642,1.466,2.67,2.998,900,1.032,906,
1.688,2.374,6.787,7.537,8.429,13.934,18.076,
17.747,17.216,13.482,7.533,7.436,5.719),
election = c(1983L,1987L,1991L,1995L,
1999L,2003L,2007L,2011L,2015L,2019L,2015L,2019L,
1983L,1987L,1991L,1995L,1999L,2003L,2007L,2011L,2015L,
2019L,2019L,2015L,2019L,2015L,1987L,1991L,1995L,
1999L,2003L,2007L,2011L,2019L,2015L,2003L,2007L,
2011L,2015L,2019L,1983L,1987L,1991L,1995L,1999L,
2003L,2007L,2011L,2015L,2019L,2011L)
I'm using this code to plot:
ggplot(party,
aes(y = value, x = as.factor(election), fill = party_name)) +
geom_bar(position = "fill", stat = "identity", width = 0.8, colour = F) +
coord_flip()
But, ggplot does not respect the order:
I want to keep the ideological spectrum, i.e.: Ex-Left, Left, Conservative, Right National, Liberal, FarRight.
Thanks.