I am trying to use putplot to change the plots on the diagonal of a ggpairs plot. I can do this one by one, but when I use a loop the diagonal elements are the same!
library(ggplot2)
library(GGally)
p=ggpairs(iris,
columns=, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"),
colour='Species',
lower=list(continuous='points'),
axisLabels='none',
upper=list(continuous='blank')
)
for (i in 1:4) {
p <- putPlot(p, ggplot(iris, aes(x=iris[,i], colour=Species)) + stat_ecdf(), i,i)
}
print(p)
Unwinding the loop works... why...?
p <- putPlot(p, ggplot(iris, aes(x=iris[,1], colour=Species)) + stat_ecdf(), 1,1)
p <- putPlot(p, ggplot(iris, aes(x=iris[,2], colour=Species)) + stat_ecdf(), 2,2)
p <- putPlot(p, ggplot(iris, aes(x=iris[,3], colour=Species)) + stat_ecdf(), 3,3)
p <- putPlot(p, ggplot(iris, aes(x=iris[,4], colour=Species)) + stat_ecdf(), 4,4)