0

Rでggplot2を使用して、次のデータでボックスプロットをプロットしようとしています:

http://dl.dropbox.com/u/105195130/test.txt

R コードは次のとおりです。

#!/usr/bin/env Rscript

library(ggplot2)

f<-read.table("test.txt", header=TRUE, sep='\t')

f$Category <- factor(f$Category, levels=unique(as.character(f$Category)))
g<-ggplot(f, aes(Category, Scores)) + stat_boxplot(geom='errorbar', linetype="dashed")
 + geom_boxplot(stat="boxplot", aes(fill=Category)) + geom_vline(linetype="dashed") + 
scale_y_log2()

ggsave("test.pdf")

次のエラーが発生しました。

Error in signif(x, digits) : 
Non-numeric argument to mathematical function

エラーをグーグルで検索し、ファイルのモードとクラスを見て、列「スコア」(2 列目) が非数値かどうかを確認しました。私にはうまく見えます。最初の列は因子で、2 番目の列は数値です。何が間違っているのか理解できません。

どんな助けでも大歓迎です。

ありがとうございました!

traceback() は以下を出力します。

19: f(unlist(l[numeric]))
18: get(x, envir = this, inherits = inh)(this, ...)
17: scales$y$labels()
16: get(x, envir = this, inherits = inh)(this, ...)
15: coord$compute_ranges(scales)
14: FUN(1:3[[1L]], ...)
13: lapply(seq_along(data), function(i) {
    layer <- layers[[i]]
    layerd <- data[[i]]
    grobs <- matrix(list(), nrow = nrow(layerd), ncol = ncol(layerd))
    for (i in seq_len(nrow(layerd))) {
        for (j in seq_len(ncol(layerd))) {
            scales <- list(x = .$scales$x[[j]]$clone(), y = .$scales$y[[i]]$clone())
            details <- coord$compute_ranges(scales)
            grobs[[i, j]] <- layer$make_grob(layerd[[i, j]], 
                details, coord)
        }
    }
    grobs
})
12: get(x, envir = this, inherits = inh)(this, ...)
11: facet$make_grobs(data, layers, cs)
10: ggplot_build(plot)
9: ggplotGrob(x, ...)
8: grid.draw(ggplotGrob(x, ...))
7: print.ggplot(plot, keep = keep, drop = drop)
6: print(plot, keep = keep, drop = drop)
5: ggsave("test.pdf") at test.R#10
4: eval(expr, envir, enclos)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("test.R")

私はRを初めて使用するので、これは意味がありません。これを使用してスクリプトをデバッグする方法を誰かが説明できれば、それは素晴らしいことです。

4

1 に答える 1

2

私のバージョンのggplot2 (0.9.3.1) には機能がありませんscale_y_log2。しかし、これは代わりに機能します:

library(scales)
g<-ggplot(tmp, aes(Category, Scores)) + 
    stat_boxplot(geom='errorbar', linetype="dashed")+ 
    geom_boxplot(stat="boxplot", aes(fill=Category)) + 
    geom_vline(linetype="dashed") + 
    scale_y_continuous(trans = log_trans(2))

0.9.0 への移行時に、scale_y_log2(他の多くのスケール機能と共に) ggplot2からscalesパッケージに移動されたと思います。あなたはおそらくアップグレードする必要があります...?

于 2013-03-28T17:08:49.870 に答える