barplot w pętli w R

Oto moje pytanie:

<code>#data 1:
lab1 <- 1:10
group <- rep(1:3, each = length (lab1))
label <- rep(lab1, 3)
avar <-  rep(c(0, 1, 4, 5, 6, 8, 10,  11, 12,  13), 3)
myd <- data.frame (group, label, avar)

# data 2
fillcol <- rep(rnorm(length(lab1)-1, 0.5, 0.2), 3)
group1 <- rep(1:3, each = length(fillcol)/3)
 # this variable will be used to fill color in bars
 filld <- data.frame(group1, fillcol)

# now plotting
par(mfrow = c(3, 1))
 par(mar = c(2.5, 1, 2.5, 1))

#plot1
myd1 <- myd[myd$group ==1,]
filld1 <- filld[filld$group1 ==1,]
blues <- colorRampPalette(c("yellow", "blue"))
barplot(as.matrix(diff(myd1$avar)), horiz=T, col=blues(10)[10* filld1$fillcol], 
 axes=F, xlab="Mark")
axis(1, labels=myd$label, at=myd$avar)
axis(3, labels=myd$avar, at=myd$avar)
</code>

Chociaż ten przykładowy zestaw danych, mam wiele zmiennych i chcę zautomatyzować ten proces.

<code>for (i in 1:length(unique(myd$group))){
         par(mfrow = c(i, 1))
        par(mar = c(2.5, 1, 2.5, 1))
                myd[i] <- myd[myd$group ==i,]
        filld[i] <- filld[filld$group1 ==i,]
      blues <- colorRampPalette(c("yellow", "blue"))
      barplot(as.matrix(diff(myd[i]$avar)), horiz=T, 
   col=blues(10)[10* filld1$fillcol], axes=F, xlab="Mark")
      axis(1, labels=myd[i]$label, at=myd[i]$avar)
        axis(3, labels=myd[i]$avar, at=myd[i]$avar)
        }
 Error in dim(data) <- dim : attempt to set an attribute on NULL
In addition: Warning messages:
1: In `[<-.data.frame`(`*tmp*`, i, value = list(group = c(1L, 1L, 1L,  :
  provided 3 variables to replace 1 variables
2: In `[<-.data.frame`(`*tmp*`, i, value = list(group1 = c(1L, 1L,  :
  provided 2 variables to replace 1 variables
</code>

Edycje: Chcę utworzyć pętlę, aby utworzyć wiele wykresów w pętli:

PS: Jestem nowy w R i stackoverflow. Przepraszam, jeśli pytanie nie jest właściwe, chociaż przeczytałem wskazówki i staram się je stosować

questionAnswers(3)

yourAnswerToTheQuestion