Trazado y posicionamiento en LaTeX de múltiples series de tiempo de múltiples archivos

I have 50 files containing 3 time series in each of them with identical tab separated format. To be specific each file contains 250 observations and looks like below:

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

The first column is obviously index and the other three columns are time series. I've written a gnuplot script to be called from another shell script in order to plot all these 50 files. But i'd like to organise these plots in such a manner that, 3x4 or 4x5 of them, to be in one A4, in a publication written with LaTeX. Is there a LaTeX package or gnuplot trick for this? Maybe it is easier to do this with R? Any suggestion is welcome.

preguntado el 03 de mayo de 12 a las 22:05

2 Respuestas

Algo como esto,



lf <- list.files(pattern=".txt")

read_file <- function(f, ...){

  result <- read.table(f, ...)
  names(result) <- c("id", "ts1", "ts2", "ts3")


## 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

## 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
plots <- dlply(m, "L1", function(d) {
  ggplot(d) + geom_path(aes(id, value, colour = variable))
ml <-, c(plots, list(nrow=3, ncol=4)))

## multipage pdf with 3x4 on each page
ggsave("multipage.pdf", ml)

(no probado)

contestado el 03 de mayo de 12 a las 23:05

This really helped, thank you! One more and last question: I've decided to follow "facetted plot strategy", as it seems more appealing to me. Question is; ts1 has a much more broader range than ts2 and ts3. Before i came here, i had written a gnuplot script which had a two y axes one for ts1 and; one for ts2 and ts3. As i've read ggplot2 documentation multiple y axes are not seen as favorable as gnuplot. So; i've decided to make two facetted plot one for ts1 and one for the remaining. Can you help me to do that? - escudo de roble1

at some point (hint: from the start) it becomes easier to discuss with some (mockup) data, so that we can propose code that actually runs. Anyway, maybe you can add a column to m above, like m$ts <- ifelse(m$variable == "ts1", "ts1", "ts23") and facet with both L1 y ts, facet_grid(ts ~ L1, scales = "free"). - bautista

Making these kinds of composite plots is really easy to do using either lattice or ggplot2. I favor ggplot2, where these kinds of composite plots are constructed using facetting. A visual teaser of how such a plot would look like (desde aquí):

p <- ggplot(diamonds, aes(carat, ..density..)) + 
  geom_histogram(binwidth = 0.2) + facet_grid(clarity ~ cut) 

enter image description here

This is a histogram, but you can quite easily draw timeseries like this. Or take a look at figure 3.6 from a report I wrote. Note that there is no need to create separate plots, ggplot2 takes care of it all, it is one big plot with a lot of subplots. Take a look at the ggplot2 docs here para obtener más detalles.

contestado el 03 de mayo de 12 a las 22:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.