我有一个森林火灾的csv文件。
数据:https://archive.ics.uci.edu/ml/machine-learning-databases/forest-fires/
我正在尝试为每个变量创建箱形图,x轴为月/日。
我不明白为什么列出变量不起作用,但是按索引引用数据框的作用。
createBox <- function(x, y) {
ggplot(data = forestFires) +
aes_string(x = x, y = y) +
geom_boxplot()
}
# code below doesn't work
# Error: Mapped vectors must have consistent lengths:
# * `.x` has length 12
# * `.y` has length 8
x_var_month <- c("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec")
x_var_day <- c("sun","mon","tue","wed","thu","fri","sat")
y_var <- c("FFMC", "DMC", "DC", "ISI", "temp", "RH", "wind", "rain")
# code below works
x_var_month <- names(forestFires)[3]
x_var_day <- names(forestFires)[4]
y_var <- names(forestFires)[5:12]
monthBox <- map2(x_var_month, y_var, createBox)
dayBox <- map2(x_var_day, y_var, createBox)
monthBox
dayBox
我认为我不需要修复代码。我只是想了解它。