Tady jsem vytvoril takovy pekny priklad na kombinovany sloupcovy stacked graf s ulozenim vysledku do souboru. Treba to nekoho inspiruje... Barvy sloupcu jsou vytipane z defaultu ms oficu.
ArgA <- "10" ArgB <- "2020" DF_SUB <- data.frame(Capacity0=runif(n = 5, min = 1, max = 5)) DF_SUB$Capacity1 <- runif(n = 5, min = 1, max = 10) DF_SUB$Capacity2 <- runif(n = 5, min = 1, max = 10) DF_SUB$Sum <- DF_SUB$Capacity0+DF_SUB$Capacity1+DF_SUB$Capacity2 DF_SUB$Eng <- round(runif(n = 5, min=1, max=6), digits = 1) DF_SUB$Cyl <- floor(runif(n = 5, min=1, max=8)) DF_SUB$Runs <- floor(runif(n = 5, min=1, max=20)) DF_SUB$Power <- runif(n = 5, min = 1, max = 10) Label0 <-"Required" colors <- c("#4f81bd", "#c0504d", "#9bbb59", "#8064a2", "#4bacc6", "#f79646", "#2c4d75", "#772c2a", "#5f7530", "#4d3b62", "#276a7c", "#b65708" ,"#729aca" ,"#cd7371", "#afc97a", "#9983b5") pngname <- gsub('\\s+', '', paste("Picture",ArgA,"-",ArgB,".png")) win.graph(width=120,height=50) par(mfrow=c(1,3)) layout(matrix(c(1,2,3),1,3,byrow = TRUE), c(5,5,2), c(5), TRUE) par(xpd=TRUE) par(mar=c(0.5,5,5,1.2)) bpl <- barplot(DF_SUB$Sum, main=paste(Label0,"Capacity ",ArgA,"/",ArgB), ylab=paste(Label0,"Capacity [kW]"),cex.lab=1.5,cex.axis=1.3,cex.main=1.5,space = 0.03,border = 1 , col=colors) bpl2 <- barplot(DF_SUB$Capacity1+DF_SUB$Capacity2,add=TRUE,cex.lab=1.5,cex.axis=1.3,cex.main=1.5,space = 0.03,border = 1 ,col = colors) bpl1 <- barplot(DF_SUB$Capacity1,add=TRUE,cex.lab=1.5,cex.axis=1.3,cex.main=1.5,space = 0.03,border = 1 ,col = "#16161650") par(xpd=FALSE) grid(NA,NULL, col = "lightgray") par(xpd=TRUE) text(bpl, DF_SUB$Sum, label = round(DF_SUB$Sum, digits = 1), pos = 3, cex = 1.8, col = "black") text(bpl, DF_SUB$Sum, label = round((DF_SUB$Sum-DF_SUB$Capacity1-DF_SUB$Capacity2), digits = 1), pos = 1, cex = 1.8, col = "black") text(bpl2, (DF_SUB$Capacity1+DF_SUB$Capacity2), label = round((DF_SUB$Capacity2), digits = 1), pos = 1, cex = 1.8, col = "black") text(bpl1, DF_SUB$Capacity1, label = round(DF_SUB$Capacity1, digits = 1), pos = 1, cex = 1.8, col = "black") par(xpd=TRUE) par(mar=c(0.5,5,5,1.2)) bpl <- barplot(DF_SUB$Power, main=paste("Engine Measurement ", ArgA,"/",ArgB), ylab="Power [kW]", cex.lab=1.5,cex.axis=1.3,cex.main=1.5,space = 0.03,border = 1 ,col=colors) par(xpd=FALSE) grid(NA,NULL, col = "lightgray") par(xpd=TRUE) text(bpl,DF_SUB$Power, label = round(DF_SUB$Power,digits=2), pos = 3, cex = 1.8, col = "black") par(xpd=TRUE) par(mar=c(1.5,5,2,1.2)) plot(5, 5, type="n", axes=FALSE, ann=FALSE, xlim=c(0, 10), ylim = c(0,10)) legenda <- paste("E",round(DF_SUB$Eng, digits = 0),"_C",round(DF_SUB$Cyl, digits = 0),"_R",round( DF_SUB$Runs,digits=0),sep = "") legend("left", inset=c(-.163,0), legenda, cex=1.5, bty="n", border = NA,fill=colors) savePlot(filename = pngname, type ="png")