I'm trying to create a bar graph that has the same variables on the x-axis except separated by year. I want to show an increase/decrease over time but I'm not sure how to insert each dataset into the graph and have the years labelled. Each dataset is election results from a specific year.
Here's one dataset for example:
1992Election
Political Party 18-29,30-44,45-59,60+ (the numbered headings are age groups)
Democrat 0.40,0.37,0.40, 0.47 (voting percentages)
Republican 0.35,0.41,0.42, 0.47
For the first dataset I have the following code to create one bar graph:
1992Election
colnames(`1992Election`)[colnames(`1992Election`)=="X.18.29."] <- "18-29"
colnames(`1992Election`)[colnames(`1992Election`)=="X.30.44."] <- "30-44"
colnames(`1992Election`)[colnames(`1992Election`)=="X.45.59."] <- "45-59"
colnames(`1992Election`)[colnames(`1992Election`)=="X.60.."] <- "60+"
Party92 = rownames(`1992Election`)
n.group92 = nrow(`1992Election`)
color.names92 = c("royalblue2", "red2")
barplot(as.matrix(`1992Election`),beside = TRUE, xlab = "Age Group",
ylab = "Percent Voted", ylim = c(0,.7), col = color.names92)
title(main = "Presidential Election Votes by Age in Ohio\n Year 1992")
legend("topright", title = "Political Party", Party92, fill = color.names92,
cex = 0.4)
this results in this graph: 1992Electiongraph
I would like to have the same variables along the x axis but grouped together by year
For ex: X- axis [the age groups (1992), [same age groups (1996), etc] if that makes sense, thanks.