继续在ggplot,geom_errbar中得到“找不到对象”的错误

时间:2015-10-19 04:10:44

标签: r ggplot2

我试图为飞行数据做一个描述性统计,并尝试使用ggplot绘制图表,但是在找不到对象的情况下继续收到错误

 ds <- flight_2010 %>%
     select(Year, Month, ArrDelay, ArrDel15) %>%
     filter(Year == 2010) %>% 
     group_by(Month)%>%
     collect()%>%
     summarise(count = n(),
        sum = sum(ArrDelay, na.rm = TRUE),
        min = min(ArrDelay, na.rm = TRUE),
        max = max(ArrDelay, na.rm = TRUE),
        mean = mean(ArrDelay, na.rm = TRUE),
        median = median(ArrDelay, na.rm = TRUE),
        range = max(ArrDelay, na.rm = TRUE)-min(ArrDelay, na.rm = TRUE),
        q1 = as.numeric(quantile(ArrDelay, na.rm = TRUE)[2]),
        q3 = as.numeric(quantile(ArrDelay, na.rm = TRUE)[4]),
        iqr = q3 - q1,
        wmin = if((q1-1.5*iqr) < min){min} else {q1 - 1.5*iqr},
        wmax = if((q3+1.5*iqr) > max){min} else {q3 + 1.5*iqr},
        sd = sd(ArrDelay, na.rm = TRUE),
        var = var(ArrDelay, na.rm = TRUE),
        se = std.error(ArrDelay, na.rm = TRUE),
        kurtosis = kurtosis(ArrDelay, na.rm = TRUE),
        skew = skewness(ArrDelay, na.rm = TRUE),
        Delay_percent = sum(ArrDel15, na.rm = TRUE) / count

  )

那里的脚本没有错误(根据rstudio)

library(ggplot2)
ggplot(flight_2010, aes(x = as.factor(Month))) +
  geom_errorbar(aes(ymin = wmin,
                    ymax = wmax)) +
  geom_boxplot(aes(lower = q1,
                   upper = q3,
                   middle = median,
                   ymin = wmin,
                   ymax = wmax), stat = "identity")

我在ds文件中写了wminwmax。这是错误

Error in eval(expr, envir, enclos) : object 'wmin' not found

感谢任何帮助。

0 个答案:

没有答案