I am working on a script to generate a statistical report for each school who has participated in a test/survey.
For that purpose i want to be able to automatically adjust the limits of x- and y axis in graphs to the specific data of each school.
For example, i would like the percentage range to be displayed 5% below and 5% above the specific data available.
As an example i have the following graph:
library(ggplot2)
library(scales)
example1 <- data.frame(stringsAsFactors=FALSE,
ID = c("Skole", "Land", "Skole", "Land", "Skole", "Land"),
value = c(0.654590909090909, 0.528446335193598, 0.631238336316461,
0.550262048394226, 0.669981060606061, 0.502430105282051),
variable = as.factor(c("Measurement and Geometry(Applying)",
"Measurement and Geometry(Applying)",
"Measurement and Geometry(Knowing)",
"Measurement and Geometry(Knowing)",
"Measurement and Geometry(Reasoning)",
"Measurement and Geometry(Reasoning)")))
item <- ggplot(example1, aes(x=variable, y=value, fill=ID)) +
geom_bar(stat="identity", position = position_dodge()) +
labs (y = "Procentdel rigtige besvarelser", title = "Matematik", x="Fagområde") +
scale_fill_manual(values=c("grey","blue")) +
coord_flip() +
guides(fill = guide_legend(reverse = TRUE)) +
theme(legend.title = element_blank()) +
scale_y_continuous(labels = percent)
item
Below is an example image:
Thank you!