I am getting data from six text files (each containing numbers separated by newlines):
args <- commandArgs(trailingOnly = TRUE)
t0 <- read.table(paste("2_",args[1],".txt",sep=""), header=FALSE, sep="\n")
t1 <- read.table(paste("4_",args[1],".txt",sep=""), header=FALSE, sep="\n")
t2 <- read.table(paste("6_",args[1],".txt",sep=""), header=FALSE, sep="\n")
t3 <- read.table(paste("8_",args[1],".txt",sep=""), header=FALSE, sep="\n")
t4 <- read.table(paste("10_",args[1],".txt",sep=""), header=FALSE, sep="\n")
t5 <- read.table(paste("12_",args[1],".txt",sep=""), header=FALSE, sep="\n")
I want to create one plot with 6 boxplots side-by-side using the same y-axis. I have consulted a similar question, but without success.
times <- matrix(c(t0,t1,t2,t3,t4,t5), ncol=6)
png(paste(args[1],".png",sep=""))
boxplot(x = as.list(as.data.frame(times)))
dev.off()
This produces the following error:
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
'x' must be atomic
Calls: boxplot ... boxplot.stats -> <Anonymous> -> sort -> sort.default -> sort.int
I'm having a hard time understanding where I am going wrong. If someone could direct me in the write path or present an alternative way of achieving my goal, it would be greatly appreciated.
Thank you.
Edit
Below is a reproducible example, upon request.
c_graph.r
:
#!/usr/bin/env Rscript
t0 <- read.table("t0.txt",header=FALSE, sep="\n")
t1 <- read.table("t1.txt",header=FALSE, sep="\n")
t2 <- read.table("t2.txt",header=FALSE, sep="\n")
times <- matrix(c(t0,t1,t2), ncol=3)
png("test.png")
boxplot(x = as.list(as.data.frame(times)))
dev.off()
t0.txt
, t1.txt
, t2.txt
(all with the same contents):
5287
5287
58
2
525
8
758
7587
587
Running the code:
Rscript c_graph.r
Results:
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
'x' must be atomic
Calls: boxplot ... boxplot.stats -> <Anonymous> -> sort -> sort.default -> sort.int