2017-03-02 22 views
2

x軸に異なる日付のtwoord.plotを使用しようとしており、lyと百分率がryの場合、軸3を削除するか色を変更します。 axes = Fを設定しても動作しません。どちらもxaxt = 'n'です。日付のある軸の処理(軸3の削除)

エラーplot.default(lx, ly, xlim = xlim, ylim = lylim, xlab = xlab,で:複数の実引数にマッチした 仮引数"axes"ソリューションはここに与えられた

Remove all axis values and labels in twoord plotはありません実際に

は、axes = FALSEは私に、このエラーメッセージを表示します異なるrxlxの私のために働かない。どのようにこのへの

set.seed(123) 
library(plotrix) 
twoord.plot(
    lx = seq(as.Date("2016-01-01"), as.Date("2017-01-01"), by = "days"), 
    ly = round(runif(367) * 6), 
    rx = seq(as.Date("2016-05-09"), as.Date("2017-01-12"), by = "days"), 
    ry = sort(rnorm(249, 60, 10)), 
    lylim = range(round(runif(367) * 6)) + c(0, 10), 
    rylim = range(sort(rnorm(249, 60, 10))) + c(-35, 10), 
    ylab.at = mean(round(runif(367) * 6)), 
    rylab.at = mean(sort(rnorm(249, 60, 10))), 
    rylab = "Percentages %", ylab = "No. of x", 
    type = c("l", "l"), lcol = "skyblue4", rcol = "chocolate1" , 
    xtickpos = as.numeric(seq(as.Date("2016-01-01"), as.Date("2017-01-01"), by = "months")), 
    xticklab = seq(as.Date("2016-01-01"), as.Date("2017-01-01"), by = "months")) 

任意のアイデア:

ここで私が使用しているものと同様のコードはありますか?前もって感謝します! :)

答えて

1

ちょうどハックtwoord.plotの機能。以下は、すべての軸ラベルを作成する例です(プロットを作成するときはtwoord.plotの代わりにtwoord.plot2を使用してください)。軸を完全に削除したい場合は、コメント行(行の前に#を追加)行88-90(ly)と行123-125(ry)を入力します。私はそれらのためのノートを以下の関数に残しました。

twoord.plot2 = function (lx, ly, rx, ry, data = NULL, main = "", xlim = NULL, 
    lylim = NULL, rylim = NULL, mar = c(5, 4, 4, 4), lcol = 1, 
    rcol = 2, xlab = "", lytickpos = NA, ylab = "", ylab.at = NA, 
    rytickpos = NA, rylab = "", rylab.at = NA, lpch = 1, rpch = 2, 
    type = "b", xtickpos = NULL, xticklab = NULL, halfwidth = 0.4, 
    axislab.cex = 1, do.first = NULL, ...) 
{ 
    if (!is.null(data)) { 
     ly <- unlist(data[ly]) 
     ry <- unlist(data[ry]) 
     if (missing(lx)) 
      lx <- 1:length(ly) 
     else lx <- unlist(data[lx]) 
     if (missing(rx)) 
      rx <- 1:length(ry) 
     else rx <- unlist(data[rx]) 
    } 
    if (missing(lx)) 
     lx <- 1:length(ly) 
    if (missing(ry)) { 
     if (missing(rx)) { 
      rx <- 1:length(ry) 
      ry <- ly 
      ly <- lx 
      lx <- 1:length(ly) 
     } 
     else { 
      ry <- rx 
      rx <- 1:length(ry) 
     } 
    } 
    oldmar <- par("mar") 
    par(mar = mar) 
    if (is.null(xlim)) 
     xlim <- range(c(lx, rx)) 
    if (missing(lx)) 
     lx <- 1:length(ly) 
    if (is.null(lylim)) { 
     lylim <- range(ly, na.rm = TRUE) 
     lyspan <- diff(lylim) 
     if (lyspan == 0) 
      lyspan <- lylim[1] 
     lylim[2] <- lylim[2] + lyspan * 0.04 
     if (lylim[1] != 0) 
      lylim[1] <- lylim[1] - lyspan * 0.04 
    } 
    if (length(type) < 2) 
     type <- rep(type, 2) 
    if (match(type[1], "bar", 0)) { 
     oldcex <- par(cex = axislab.cex) 
     plot(lx, ly, xlim = xlim, ylim = lylim, xlab = xlab, 
      ylab = "", yaxs = "i", type = "n", main = "", axes = FALSE, 
      ...) 
     par(oldcex) 
     if (!is.null(do.first)) 
      eval(parse(text = do.first)) 
     ybottom <- par("usr")[3] 
     if (lylim[1] < 0) 
      abline(h = 0, lty = 2) 
     rect(lx - halfwidth, ifelse(ly < 0, ly, ybottom), lx + 
      halfwidth, ifelse(ly > 0, ly, 0), col = lcol) 
    } 
    else { 
     oldcex <- par(cex = axislab.cex) 
     plot(lx, ly, xlim = xlim, ylim = lylim, xlab = xlab, 
      ylab = "", yaxs = "i", type = "n", main = "", axes = FALSE, 
      ...) 
     par(oldcex) 
     if (!is.null(do.first)) 
      eval(parse(text = do.first)) 
     points(lx, ly, col = lcol, pch = lpch, type = type[1], 
      ...) 
    } 
    title(main = main) 
    xylim <- par("usr") 
    box() 
    if (is.null(xticklab)) 
     axis(1, cex.axis = axislab.cex) 
    else { 
     if (is.null(xtickpos)) 
      xtickpos <- 1:length(xticklab) 
     axis(1, at = xtickpos, labels = xticklab, cex.axis = axislab.cex) 
    } 
    if (is.na(lytickpos[1])) 
     lytickpos <- pretty(ly) 
    if (is.na(ylab.at)) 
     ylab.at <- mean(lytickpos) 
    color.axis(2, at = lytickpos, axlab = ylab, axlab.at = ylab.at, #LINE 88 
     col = "black", cex.axis = axislab.cex, #col = ifelse(is.na(lcol), 1, lcol), cex.axis = axislab.cex, 
     cex = axislab.cex) #LINE 90 
    if (is.null(rylim)) { 
     rylim <- range(ry, na.rm = TRUE) 
     ryspan <- diff(rylim) 
     if (ryspan == 0) 
      ryspan <- rylim[1] 
     rylim[2] <- rylim[2] + ryspan * 0.04 
     if (rylim[1] != 0) 
      rylim[1] <- rylim[1] - ryspan * 0.04 
    } 
    ymult <- diff(lylim)/diff(rylim) 
    yoff <- lylim[1] - rylim[1] * ymult 
    if (match(type[2], "bar", 0)) { 
     if (rylim[1] < 0) 
      abline("h", 0) 
     rect(rx - halfwidth, ifelse(ry < 0, ry, rylim[1] * ymult + 
      yoff), rx + halfwidth, ifelse(ry > 0, ry * ymult + 
      yoff, 0), col = rcol) 
    } 
    else points(rx, ry * ymult + yoff, col = rcol, pch = rpch, 
     type = type[2], ...) 
    if (is.na(rytickpos[1])) 
     rylabels <- pretty(rylim) 
    else rylabels <- rytickpos 
    if (min(rylabels) < rylim[1]) 
     rylabels <- rylabels[rylabels >= rylim[1]] 
    if (max(rylabels) > rylim[2]) 
     rylabels <- rylabels[rylabels <= rylim[2]] 
    axat <- rylabels * ymult + yoff 
    if (is.na(rylab.at)) 
     rylab.at <- mean(rytickpos) 
    if (!is.na(rylab.at)) 
     rylab.at <- rylab.at * ymult + yoff 
    color.axis(4, at = axat, labels = rylabels, axlab = rylab, #LINE 123 
     axlab.at = rylab.at, col = "black", #axlab.at = rylab.at, col = ifelse(is.na(rcol), 1, rcol), 
     cex.axis = axislab.cex, cex = axislab.cex) #LINE 125 
    par(mar = oldmar, new = FALSE, col.axis = "black") 
} 
+1

ありがとうございました!私はなんとかした! :) – Lil