I want to show statistics of five countries, to each country I have 4 values of each year (2000, 2004, 2008, 2012). The code is fine, but I have one main problem with colors, the color of each field is not fix, for example for one country the color sequence is (blue for 1st filed, red for 2ed filed, ..) but with another country the sequence is different.
another problem with legend, only 2 values out of 5 appear
Here is the code :
par(mfrow=c(3,2),oma=c(5,0,0,0),xpd=NA)
par(mar=c(4,4,2,2))
schoolenrollment <- read.csv(file.choose(), header=T, sep=",")
country <- c("Comoros","Jordan","United Arab Emirates","Egypt"," Qatar")
y=1
z=4
for (x in seq(from=1, to=20, by=4))
{
barplot(as.matrix(schoolenrollment[x:z]), main=country[y],
ylab= "Total Number", beside=TRUE, col=rainbow(4))
y=y+1
z=z+4
}
legend(-0.5, 3.5, ncol=2,
c("School enrollment, preprimary (% gross)",
" School enrollment, primary (% gross)",
" School enrollment, secondary (% gross)",
"School enrollment, secondary(% gross)",
"School enrollment, tertiary (% gross)"),
cex=0.9, bty="n", fill=rainbow(4));
dataset: https://drive.google.com/file/d/0B1NJGKqdrgRta0R2ZFlZemVtRFE/edit?usp=sharing
I tried to use fix colors ,,, but its the same problem:
par(mfrow=c(3,2),oma=c(5,0,0,0),xpd=NA)
par(mar=c(4,4,2,2))
schoolenrollment<- read.csv(file.choose(), header=T, sep=",")
country<- c("Comoros","Jordan","United Arab Emirates","Egypt"," Qatar")
y=1
z=4
for (x in seq(from=1, to=20, by=4))
{
barplot(as.matrix(schoolenrollment[x:z]), main=country[y], ylab= "Total Number",
beside=TRUE, col=c("red","blue","green","yellow"))
y=y+1
z=z+4
}
legend(-0.5,3.5,ncol=2, c("School enrollment, preprimary (% gross)", " School enrollment, primary (% gross)"," School enrollment, secondary (% gross)","School enrollment, secondary(% gross)", "School enrollment, tertiary (% gross)"), cex=0.9, bty="n", fillc("red","blue","green","yellow"));