Dataset looks like this and is entitled rotterdam3
I am trying to get this into a stacked bar with just one bin that is the party's stacked on top of each other with the percent of the vote share they won. My code now is the following. I know my problem..its because the Party variable has two things in it so it won't put it into one variable. I am unsure how to change this. I tried to take out the x argument, but ggplot doesn't allow that with geombar.
ggplot(rotterdamparty3, aes(Party, PercVote, fill=Variable)) +
geombar(stat="identity")
xlab("Party") +
ylab("Percent of vote share") +
ggtitle("Total Cote Share between VVD and PVV in Rotterdam") +
theme(axis.title.x=element_blank(),
scale_fill_manual(values=c("darkblue, "chocolate3"), labels=c("VVD", "PVV")) +
theme(text=element_text(size=14, vjust=1, family="Trebuchet MS")) +
theme(panel.background = element_rect(fill='gray95', colour='white'))
Your code had some errors in it. I took the liberty to fix the code and make a quick data.frame.
library(ggplot2)
library(reshape2)
## make data.frame:
rotterdamparty3 <- data.frame(Party=c("PVV TK17", "VVD TK17"),
Variable=c("PVV", "VVD"),
RawVote=c(50260, 51661),
PercVote=c(49.3127, 50.6873))
## edit: geombar -> geom_bar,
## edit: put "+" after geom_bar()
## edit: "darkblue -> "darkblue"
## edit: "Cote" -> "Vote"
## edit: moved first theme() instance and closed parenthesis.
ggplot(rotterdamparty3, aes(Party, PercVote, fill=Variable)) +
geom_bar(stat="identity") +
xlab("Party") +
ylab("Percent of vote share") +
ggtitle("Total Vote Share between VVD and PVV in Rotterdam") +
scale_fill_manual(values=c("darkblue", "chocolate3"),
labels=c("VVD", "PVV")) +
theme(axis.title.x=element_blank(),
text=element_text(size=14, vjust=1, family="Trebuchet MS"),
panel.background = element_rect(fill='gray95', colour='white'))
Create a "dummy" X variable that has the same value for the different parties if you want everything in one bar. Also, be aware, I think the way you specified the labels in the Question actually switched which of the Parties had which value of PercVote --- I commented the labels out and let ggplot2 handle it automatically. If the colors are not ascribed to the right party just switch the order of the colors in the code below.
## Create X
rotterdamparty3$X <- " "
## Put X into aes()
ggplot(rotterdamparty3, aes(X, PercVote, fill=Variable)) +
geom_bar(stat="identity")+
xlab("Party") +
ylab("Percent of vote share") +
ggtitle("Total Vote Share between VVD and PVV in Rotterdam") +
scale_fill_manual(values=c("darkblue", "chocolate3")#,
#labels=c("VVD", "PVV")
) +
theme(axis.title.x=element_blank(),
text=element_text(size=14, vjust=1, family="Trebuchet MS"),
panel.background = element_rect(fill='gray95', colour='white'))