Your data isn't in the best format to achieve what you want.
Please try:
dd <- read.table(file = '\Stackoverflow\\22449135\\schoolenrollment.csv',
header = T, dec = '.', sep = ',')
d <- data.frame('Value'=unname(as.matrix(unlist(dd[1:4, ]),ncol = 1,
nrow=80, byrow = F))[,1],
'Country' =rep(c('Comoros', 'Jordan', 'U A Emirates',
'Egypt', 'Qatar'), each = 16),
'Year' =rep(c(2000, 2004, 2008, 2012), each = 4, times = 5),
'Enrollment' = rep(c("Prelimary", "Primary", "Secondary",
"Tertiary"), times = 5))
library(ggplot2)
ggplot(data = d) +
geom_bar(aes(x=factor(Year), y=Value, fill = Enrollment),
stat = 'identity', position = 'dodge') +
facet_wrap(~Country) +
labs(list(x = 'Year', y = '% gross'))
or
ggplot(data = d) +
geom_bar(aes(x=factor(Year), y=Value, fill = Enrollment),
stat = 'identity', position = 'dodge') +
facet_grid(Country ~.) +
labs(list(x = 'Year', y = '% gross'))
or with gridExtra::grid.arrange
g1 <- ggplot(data = d[d$Country == 'Comoros', ]) +
geom_bar(aes(x=factor(Year), y=Value, fill = Enrollment),
stat = 'identity', position = 'dodge') +
labs(list(x = 'Year', y = '% gross'))
g2 <- ggplot(data = d[d$Country == 'Jordan', ]) +
geom_bar(aes(x=factor(Year), y=Value, fill = Enrollment),
stat = 'identity', position = 'dodge') +
labs(list(x = 'Year', y = '% gross'))
g3 <- ggplot(data = d[d$Country == 'U A Emirates', ]) +
geom_bar(aes(x=factor(Year), y=Value, fill = Enrollment),
stat = 'identity', position = 'dodge') +
labs(list(x = 'Year', y = '% gross'))
grid.arrange(g1,g2, g3)
or manage legends with grobs.