My data looks like this:
structure(list(Answer = structure(c(4L, 3L, 1L, 2L, 4L, 3L, 1L
), .Label = c("Unsure", "Project-dependent", "No", "Yes"), class = "factor"),
Monitoring = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("Pre-restortation",
"Post-restoration"), class = "factor"), Percent = c(32L,
55L, 9L, 4L, 77L, 19L, 2L)), row.names = c(NA, -7L), class = "data.frame")
I've plotted it using ggplot2
ggplot(d1, aes(x=Monitoring, y=Percent)) +
geom_bar(stat = "identity", position = position_dodge2(width = 0.9, preserve = "single"), aes(fill = d1$Answer), width = 0.7, color="black") +
scale_x_discrete(limits = rev(levels(d1$Monitoring))) +
scale_y_continuous(name = "Percentage of respondents (%)") +
scale_fill_manual(values=cols) + theme(panel.grid.major.x = elemdent_blank()) +
coord_flip() +
geom_text(aes(label = Percent, group = Answer),hjust=-0.2, position = position_dodge2(0.7,preserve="single"), size=2.7)
My problem is that I want the Answer levels that are currently listed in the legend, shown on the x-axis (y-axis when flipped) as axis labels for each bar