Reputation: 1043
I'm trying to plot a boxplot using ggplot2 in R with the following data:
http://dl.dropbox.com/u/105195130/test.txt
The R code is as follows:
#!/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")
I got the following error:
Error in signif(x, digits) :
Non-numeric argument to mathematical function
I tried to google the error and verified if column 'Scores' (2nd column) is non-numeric by looking at mode and class of the file. It looks fine to me. The first column is factor and second column is numeric. I'm unable to understand what is it that I'm doing wrong.
Any help is greatly appreciated.
Thank you!
traceback() prints the following:
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")
I'm new to R so this doesn't make sense to me, if anyone can explain how can I debug my script using this that will be great.
Upvotes: 0
Views: 2093
Reputation: 173677
My version of ggplot2 (0.9.3.1) doesn't have a scale_y_log2
function. But this works instead:
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))
I believe that scale_y_log2
(along with much of the other scales functionality) was moved out of ggplot2 and into the scales package back in the transition to 0.9.0. You should maybe upgrade...?
Upvotes: 2