Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何确定互动的传奇。情节?_R - Fatal编程技术网

R 如何确定互动的传奇。情节?

R 如何确定互动的传奇。情节?,r,R,我想画出不同样带中一堆橡树的年生长量。因此,我测量了2019年、2018年和2017年的增长,并希望用交互图展示数据。 我的问题是我探测的树的数量。我有25个样条,当我尝试在一个框架上合并所有4个地块时,问题变得更糟 我尝试使用y.instersp就像你可以使用普通图例一样。但这会产生一个警告(y.intersp不是grafic参数),并且似乎对绘图没有影响。对于interaction.plot是否有替代方案 我制作了一些样本数据: par(mfrow = c(2, 2),oma = c(0,

我想画出不同样带中一堆橡树的年生长量。因此,我测量了2019年、2018年和2017年的增长,并希望用交互图展示数据。 我的问题是我探测的树的数量。我有25个样条,当我尝试在一个框架上合并所有4个地块时,问题变得更糟

我尝试使用
y.instersp
就像你可以使用普通图例一样。但这会产生一个警告(y.intersp不是grafic参数),并且似乎对绘图没有影响。对于interaction.plot是否有替代方案

我制作了一些样本数据:

par(mfrow = c(2, 2),oma = c(0, 0, 2, 0)) # this worsens the problem, but it already exists without mfrow 
l2017 <- rnorm(1:25, 5)
l2018 <- rnorm(1:25, 8)
l2019 <- rnorm(1:25, 7)
TreeID <- sample(1:100, 25, replace=FALSE)
before.new <- data.frame(centimetre = l2017, Measurement = "2017", 
                         unit = TreeID)
middle.new <- data.frame(centimetre = l2018, Measurement = "2018", 
                         unit = TreeID)
after.new <- data.frame(centimetre = l2019, Measurement = "2019", 
                        unit = TreeID)
df.new <- rbind(before.new, middle.new, after.new)
#create plot
interaction.plot(df.new$Measurement, df.new$unit, df.new$centimetre, ylab = "Centimetre", xlab = "Measurement", 
                 col = df.new$unit, trace.label = "TreeID", xpd = T, lty=1, fixed = T, type ="b", leg.bty = T,
                 main = "Transect 1", pch = c(1:nrow(df.new)))

mtext("Oak increase 2017 - 2019", outer = TRUE, cex = 1.5)
par(mfrow=c(2,2),oma=c(0,0,2,0))#这会使问题恶化,但在没有mfrow的情况下问题已经存在

l2017在下面,您可以找到一个修改版的
interaction.plot
,其中添加了一些新的图例参数(
x.intersp
y.intersp
leg.pt.cex
leg.cex
):

生成的图是


非常感谢!这比我想象的要多得多!
myinteraction.plot <- function (x.factor, trace.factor, response, fun = mean, 
    type = c("l", "p", "b", "o", "c"), legend = TRUE, 
    trace.label = deparse(substitute(trace.factor)), 
    fixed = FALSE, xlab = deparse(substitute(x.factor)), ylab = ylabel, 
    ylim = range(cells, na.rm = TRUE), lty = nc:1, col = 1, pch = c(1L:9, 
        0, letters), xpd = NULL, leg.bg = par("bg"), leg.bty = "n", 
    xtick = FALSE, xaxt = par("xaxt"), x.intersp = 1, y.intersp = 1, 
    leg.cex = 1, leg.pt.cex = leg.cex, axes = TRUE, ...) {
    ylabel <- paste(deparse(substitute(fun)), "of ", deparse(substitute(response)))
    type <- match.arg(type)
    cells <- tapply(response, list(x.factor, trace.factor), fun)
    nr <- nrow(cells)
    nc <- ncol(cells)
    xvals <- 1L:nr
    if (is.ordered(x.factor)) {
        wn <- getOption("warn")
        options(warn = -1)
        xnm <- as.numeric(levels(x.factor))
        options(warn = wn)
        if (!anyNA(xnm)) 
            xvals <- xnm
    }
    xlabs <- rownames(cells)
    ylabs <- colnames(cells)
    nch <- max(sapply(ylabs, nchar, type = "width"))
    if (is.null(xlabs)) 
        xlabs <- as.character(xvals)
    if (is.null(ylabs)) 
        ylabs <- as.character(1L:nc)
    xlim <- range(xvals)
    xleg <- xlim[2L] + 0.05 * diff(xlim)
    xlim <- xlim + c(-0.2/nr, if (legend) 0.2 + 0.02 * nch else 0.2/nr) * 
        diff(xlim)
    dev.hold()
    on.exit(dev.flush())
    matplot(xvals, cells, ..., type = type, xlim = xlim, ylim = ylim, 
        xlab = xlab, ylab = ylab, axes = axes, xaxt = "n", col = col, 
        lty = lty, pch = pch)
    if (axes && xaxt != "n") {
        axisInt <- function(x, main, sub, lwd, bg, log, asp, 
            ...) axis(1, x, ...)
        mgp. <- par("mgp")
        if (!xtick) 
            mgp.[2L] <- 0
        axisInt(1, at = xvals, labels = xlabs, tick = xtick, 
            mgp = mgp., xaxt = xaxt, ...)
    }
    if (legend) {
        yrng <- diff(ylim)
        yleg <- ylim[2L] - 0.1 * yrng
        if (!is.null(xpd) || {
            xpd. <- par("xpd")
            !is.na(xpd.) && !xpd. && (xpd <- TRUE)
        }) {
            op <- par(xpd = xpd)
            on.exit(par(op), add = TRUE)
        }
        text(xleg, ylim[2L] - 0.05 * yrng, paste("  ", trace.label), 
            adj = 0)
        if (!fixed) {
            ord <- sort.list(cells[nr, ], decreasing = TRUE)
            ylabs <- ylabs[ord]
            lty <- lty[1 + (ord - 1)%%length(lty)]
            col <- col[1 + (ord - 1)%%length(col)]
            pch <- pch[ord]
        }
        legend(xleg, yleg, legend = ylabs, col = col, pch = if (type %in% 
            c("p", "b")) 
            pch, lty = if (type %in% c("l", "b")) 
            lty, bty = leg.bty, bg = leg.bg, x.intersp=x.intersp, y.intersp=y.intersp, 
            cex=leg.cex, pt.cex=leg.pt.cex)
    }
    invisible()
}
par(mfrow = c(2, 2), oma = c(0, 0, 2, 0)) 
l2017 <- rnorm(1:25, 5)
l2018 <- rnorm(1:25, 8)
l2019 <- rnorm(1:25, 7)
TreeID <- sample(1:100, 25, replace=FALSE)
before.new <- data.frame(centimetre = l2017, Measurement = "2017", unit = TreeID)
middle.new <- data.frame(centimetre = l2018, Measurement = "2018", unit = TreeID)
after.new <- data.frame(centimetre = l2019, Measurement = "2019",  unit = TreeID)
df.new <- rbind(before.new, middle.new, after.new)

myinteraction.plot(df.new$Measurement, df.new$unit, df.new$centimetre, 
      ylab = "Centimetre", xlab = "Measurement",  col = df.new$unit, 
      trace.label = "TreeID", xpd = T, lty=1, fixed = T, type ="b", 
      leg.bty = T,  main = "Transect 1", pch = c(1:nrow(df.new)), 
      x.intersp=.6, y.intersp=.6, leg.pt.cex=.6, leg.cex=.6)