I want to do this with barplot() for having the same design and as a challange. I took this system from Thomas as template: R: bar plot with two groups, of which one is stacked which really worked great! My data.frame is:
'data.frame': 14 obs. of 4 variables:
$ Lw_Eink : int 64675 52434 51500 55029 60472 54274 52915 61143 64147 60305 ...
$ Alw_Eink: int 19208 18633 18577 21210 21557 22172 22939 23417 24131 26204 ...
$ HH_EE : int 72740 74214 76576 75623 73725 78426 76264 80762 83474 84640 ...
$ HH_AEE : int 28701 29037 29210 29751 28350 29179 26348 28215 25765 27788 ...
and my suggested script:
lw = c(as.numeric(h$Lw_Eink))
alw = c(as.numeric(h$Alw_Eink))
hh = c(as.numeric(h$HH_EE))
ahh = c(as.numeric(h$HH_AEE))
vh = cbind(rbind(lw,alw,0,0),rbind(0,0,hh,ahh))[,c(1,29,2,30,3,31,4,32,5,33,6,34,7,35,8,36,9,37,10,38,11,39,12,40,13,41,14,42,15,43,
16,44,17,45,18,46,19,47,20,48,21,49,22,50,23,51,24,52,25,53,26,54,27,55,28,56)]
barplot(vh,
main="ø Einkommen LWS-Betriebe : ø Haushaltseinkommen CH 1998-2014",
xlab="Jahr",
ylab="Einkommen [CHF]",
ylim=c(0, 100000),
las=3,
col=c("forestgreen","blue","orange","darkolivegreen1","cornflowerblue"),
cex.axis = 0.9, cex.lab = 1, cex.names=0.9,
names.arg = expression("2000","","","","2001","","","","2002","","","","2003","","","","2004","","","","2005","","","","2006",
"","","","2007","","","","2008","","","","2009","","","","2010","","","","2011","","","","2012","","","","2013","","","")[1:56],
space=c(.9,.2))
grid(nx=NA,ny=10,col="darkgrey")
grid(nx=NA,ny=NULL,col="darkgrey")
legend("topleft",
c("Landwirt. Einkommen","Ausserlandwirt. Einkommen", "HH Erwerbseinkommen", "HH Aussererwerbseinkommen"),
fill=c("forestgreen","blue","orange","darkolivegreen1","cornflowerblue"),cex=0.7)
First Error is:
Error in cbind(rbind(lw, alw, 0, 0), rbind(0, 0, hh, ahh))[, c(1, 29, :
subscript out of bounds
And second:
Error in barplot.default(vh, main = "ø Einkommen LWS-Betriebe : ø Haushaltseinkommen CH 1998-2014", :
falsche Anzahl von Namen
Second means: wrong quantity of numbers...
Data h is:
Lw_Eink Alw_Eink HH_EE HH_AEE
2000 64675 19208 72740 28701
2001 52434 18633 74214 29037
2002 51500 18577 76576 29210
2003 55029 21210 75623 29751
2004 60472 21557 73725 28350
2005 54274 22172 78426 29179
2006 52915 22939 76264 26348
2007 61143 23417 80762 28215
2008 64147 24131 83474 25765
2009 60305 26204 84640 27788
2010 55182 26308 88324 27103
2011 59474 26737 87252 27998
2012 55965 26772 90950 29809
2013 61386 27127 91414 29206
I know it's reeaally inconvenient... but I would love to have it in the same design like the rest of my semester-work.