When reading this, please bear in mind I have been working in R for about 3 days only. I have loaded general election data and managed to successfully plot a barchart showing Labour votes in Ludlow since 1955. I also managed to create a table in long format showing votes for all parties in Ludlow since 1955 and am trying to turn this into a bar chart. Afraid this has stumped my small brain This code will create a chart with votes for Labour since 1955:
GEdata %>%
filter(Name == "Ludlow") %>%
select(year,LAB) %>%
ggplot(aes(x = year, y = LAB)) +
geom_bar(stat="identity", fill="red")+
geom_text(aes(label=LAB), vjust=1.6, color="white", size=3.5)+
theme_minimal() +
labs(title = "Labour Vote in Ludlow since 1955",
colour = NULL,
y = NULL,
x = NULL) +
theme(legend.position = "bottom")
But I cannot do two things I want (1) Show a bar-chart with votes and appropriate colours for each party for any one election (2) Create a chart showing bar-plots for all elections since 1955 with year as a x axis, votes as y axis and for each year bar--plots in appropriate colours for each party. I have created a file in long format to enable this and the data is as follows:
Ludlow <- GEdata %>%
filter(Name == "Ludlow",na.rm =TRUE) %>%
select(year,LAB,CON,LIB,MIN,OTH,UKIP,Green)
This is converted to long format:
Ludlowlong <- Ludlow %>% gather(key = "Year", value = "votes", (LAB:Green), na.rm =TRUE)
I am sure there are plenty of errors here but at least it forms a datafile. So the date file lists all votes for all parties since 1955 as follows:
A tibble: 95 x 3
year Party votes
<chr> <chr> <dbl>
1 1955 LAB 12937
2 1959 LAB 14138
3 1964 LAB 10763
4 1966 LAB 16123
5 1970 LAB 12800
6 1974feb LAB 9035
7 1974oct LAB 8353
8 1979 LAB 5717
9 1983 LAB 5949
10 1987 LAB 7724
... with 85 more rows
What I want is a bar plot with the votes for parties on the y axis, and either parties on the x axis if only covering one year or preferably combining to allow all years. Hopefully this provides enough detail Thanks for any assistance
Apologies for any ignorance. Hopefully this is the info on the data-set you asked for.
structure(list(year = c("1955", "1959", "1964", "1966", "1970",
"1974feb", "1974oct", "1979", "1983", "1987", "1992ob", "1997",
"2001ob", "2005ob", "2010", "2015", "2017", "2019", "1955", "1959",
"1964", "1966", "1970", "1974feb", "1974oct", "1979", "1983",
"1987", "1992ob", "1997", "2001ob", "2005ob", "2010", "2015",
"2017", "2019", "1955", "1959", "1964", "1966", "1970", "1974feb",
"1974oct", "1979", "1983", "1987", "1992ob", "1997", "2001ob",
"2005ob", "2010", "2015", "2017", "2019", "1955", "1959", "1964",
"1966", "1970", "1974feb", "1974oct", "1979", "1983", "1987",
"1992ob", "1997", "2001ob", "2005ob", "2010", "2015", "2017",
"2019", "1955", "1959", "1964", "1966", "1970", "1974feb", "1974oct",
"1979", "1983", "1987", "1992ob", "1997", "2001ob", "2005ob",
"2010", "2015", "2017", "2019", "2015", "2017", "2015", "2017",
"2019"), Party = c("LAB", "LAB", "LAB", "LAB", "LAB", "LAB",
"LAB", "LAB", "LAB", "LAB", "LAB", "LAB", "LAB", "LAB", "LAB",
"LAB", "LAB", "LAB", "CON", "CON", "CON", "CON", "CON", "CON",
"CON", "CON", "CON", "CON", "CON", "CON", "CON", "CON", "CON",
"CON", "CON", "CON", "LIB", "LIB", "LIB", "LIB", "LIB", "LIB",
"LIB", "LIB", "LIB", "LIB", "LIB", "LIB", "LIB", "LIB", "LIB",
"LIB", "LIB", "LIB", "MIN", "MIN", "MIN", "MIN", "MIN", "MIN",
"MIN", "MIN", "MIN", "MIN", "MIN", "MIN", "MIN", "MIN", "MIN",
"MIN", "MIN", "MIN", "OTH", "OTH", "OTH", "OTH", "OTH", "OTH",
"OTH", "OTH", "OTH", "OTH", "OTH", "OTH", "OTH", "OTH", "OTH",
"OTH", "OTH", "OTH", "UKIP", "UKIP", "Green", "Green", "Green"
), votes = c(12937, 14138, 10763, 16123, 12800, 9035, 8353, 5717,
5949, 7724, 11709, 11745, 5785, 4974, 3272, 5902, 12147, 7591,
20816, 21464, 17290, 19603, 22104, 18674, 17124, 20906, 26278,
27499, 28719, 19633, 16990, 20979, 25720, 26093, 31433, 32185,
0, 0, 8768, 0, 5444, 10687, 10888, 12524, 0, 15800, 14567, 13724,
18620, 18952, 15971, 6469, 5336, 8537, 0, 0, 0, 0, 0, 0, 0, 0,
14975, 0, 0, 0, 0, 0, 2127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 460,
0, 0, 758, 1183, 1456, 1635, 1642, 0, 0, 0, 7164, 0, 2435, 1054,
1912)), row.names = c(NA, -95L), class = c("tbl_df", "tbl", "data.frame"
))
So the examples provided are indeed the sort of thing I want. However there are more parties and appropriate colours needed ( Lab = red, Conservative = Blue, UKIP = Purple, Green = Green, LD = Orange, Min + Grey
Hopefully this provides the data