oak*_*ld1 0 latex r gnuplot ggplot2
我有50个文件,每个文件包含3个时间序列,每个文件都有相同的制表符分隔格式 具体来说,每个文件包含250个观察结果,如下所示:
1 8.83229 0.02544 0.02544
2 2.95561 0.02544 0.02544
3 1.27395 0.02544 0.02544
4 2.01115 0.02544 0.02544
5 2.38058 0.02383 0.02383
6 1.10755 0.02383 0.02383
7 1.16735 0.02013 0.02013
8 1.57755 0.02013 0.02013
9 1.81942 0.02013 0.02013
10 1.45921 0.01611 0.01611
...
246 0.04564 0.02383 0.01611
247 0.04357 0.02383 0.01611
248 0.03651 0.02383 0.01611
249 0.03334 0.02383 0.01611
250 0.03438 0.02383 0.01611
Run Code Online (Sandbox Code Playgroud)
第一列显然是索引,其他三列是时间序列.我编写了一个gnuplot脚本,可以从另一个shell脚本调用,以便绘制所有这50个文件.但是我想以这样一种方式组织这些情节,即用LaTeX编写的出版物中的3x4或4x5,在一个A4中.是否有LaTeX包或gnuplot技巧?使用R可能更容易做到这一点?任何建议都是受欢迎的.
像这样的东西,
library(reshape2)
library(plyr)
library(ggplot2)
setwd("/Users/baptiste/data/")
lf <- list.files(pattern=".txt")
read_file <- function(f, ...){
result <- read.table(f, ...)
names(result) <- c("id", "ts1", "ts2", "ts3")
result
}
## read all files in a list
all <- llply(lf, read_file, .progress="text")
names(all) <- paste0("file", seq_along(all))
m <- melt(all, id = "id") # to long format
str(m)
## facetted plot
ggplot(m) + facet_wrap( ~ L1, ncol = 4 ) +
geom_path(aes(id, value, colour = variable))
ggsave("facetted_plot.pdf", width = 10, height = 10)
## alternative: multiple plots
library(gridExtra)
plots <- dlply(m, "L1", function(d) {
ggplot(d) + geom_path(aes(id, value, colour = variable))
})
ml <- do.call(marrangeGrob, c(plots, list(nrow=3, ncol=4)))
ml
## multipage pdf with 3x4 on each page
ggsave("multipage.pdf", ml)
Run Code Online (Sandbox Code Playgroud)
(另)
| 归档时间: |
|
| 查看次数: |
308 次 |
| 最近记录: |