0
親愛的StackOverflow社區,處理ggplot2和for循環
多年來,我一直在社區尋求幫助。感謝那。現在我自己有一個問題:
我想在for循環列表中存儲多個ggplot圖。代碼運行時沒有錯誤,但僅打印最後一個圖的數據。
# Preparation
metr_var <- c("schneehoehe",
"wind_richtung",
"wind_vmittel",
"wind_vmax",
"temp",
"luftfeuchtigkeit"
)
# Generating List
plot_list <- list()
# For Loop
for (j in metr_var) {
p = ggplot(data = NULL, aes_string(x = arfang$arfang, y = arfang[, j]))
+ geom_boxplot() + ylab(j) + theme_bw()
dev.new()
plot_list[[which(metr_var == j)]] = print(p)
}
現在,如果我運行的代碼,只能從最後 ggplot命令,AES是印刷。所以每個圖形都用不同的y軸打印,但數據保持不變。
我知道它與ggplot和aes有關,但我只是想知道問題是什麼。我搜索了整個StackOverflow和其他建議(打印,dev.new等)沒有幫助。
感謝任何幫助我的人。 斯坦
'ggplot(數據= arfang,aes_string(X = 「arfang」,Y = j)的)' – Roland
感謝羅蘭!你和朱巴的回答幫了我:) – Stan125