为什么数据和数据$ value在ggplot和geom_line中的工作方式不同?

时间:2017-06-11 13:53:47

标签: r ggplot2

我有以下R代码,用名为probData_com的列表格式从给定数据中绘制。这段代码很好,但问题是如果我更换" rank"," value"," variable"在ggplot内部和geom_line由dat $ rank,dat $ value和dat $ variable组成,然后' g'只显示最后一个情节三次。谁能告诉我为什么会这样?

    g <- list()
    for(i in 1:3)
    {
        probData <- probData_com[[i]]
        colnames(probData) <- c("ranks","SH0","SH1","EH0","EH1","AH0","AH1")
        dat <- melt(probData, id.var = "ranks")

        ey_val <- ifelse(effectType == "binary", i-1,
                         ifelse(i==1, 0, paste0("U(",i-2,", ", i-1,")")))
        eySm <- ifelse(effectType == "binary", "ey = ", "ey ~ ")

        g[[i]] = ggplot(dat, aes(x = ranks, y = value, group = variable,
                                 colour = variable)) +
            geom_line(aes(linetype = variable), size = 1.5) +
            labs(x = "Ranks", y = "p(rank | effect)", size = 20,
                 subtitle = paste0(eySm, ey_val, ", e.one = ", e.one)) +
            theme(legend.title = element_blank(),
                  axis.title.x = element_text(size = rel(.7)),
                  axis.title.y = element_text(size = rel(.7)))
    }

0 个答案:

没有答案