Plotting an average line in ggplot.
I have the following data;
structure(list(Region.in.country = c("Andalucia", "Aragon", "Asturias",
"Canary Islands", "Cantabria", "Castilla-La Mancha", "Castilla y Leon",
"Cataluna", "Comunidad Valenciana", "Extremadura", "Galicia",
"Islas Baleares", "La Rioja", "Madrid", "Murcia", "Navarra",
"Pais Vasco"), count = c(540L, 117L, 74L, 362L, 36L, 150L, 299L,
952L, 797L, 72L, 283L, 353L, 39L, 1370L, 302L, 46L, 255L)), .Names = c("Region.in.country",
"count"), row.names = c(NA, -17L), class = c("tbl_df", "tbl",
"data.frame"), na.action = structure(18L, .Names = "18", class = "omit"))
I am trying to add an average line across the bar plot in ggplot 2. The average line is the avergae of the count
column over the 17 regions.
sum(region$count) / 17
ggplot(data = region, aes(x = Region.in.country, y = count)) +
geom_bar(stat="identity") +
geom_line(data = region, aes(355.7059)) +
coord_flip()
The above code returns an error
EDIT: