Documento realizado el |
[1] "Tue Oct 4 19:55:11 2022"
Ocuparemos la dataframe orange2 del paquete datana del libro Análisis de datos con el programa estadístico R: una introducción aplicada de Salas-Eljatib (2021).
library(datana)
data(orange2)
df <- orange2
head(df) #primeras seis filas
arbol.no tiempo peri dap sitio especie
1 1 118 30 9.5493 Northern site Radiata pine
2 1 484 58 18.4620 Northern site Radiata pine
3 1 664 87 27.6930 Northern site Radiata pine
4 1 1004 115 36.6056 Northern site Radiata pine
5 1 1231 120 38.1972 Northern site Radiata pine
6 1 1372 142 45.2000 Northern site Radiata pine
nrow(df) #numero de filas de la dataframe
[1] 35
Esta dataframe contiene mediciones temporales de diametro a la altura del pecho en arboles de Naranjo, esto es un estudio longitudinal, es decir, existen varias mediciones para cada unidad muestral. Ejemplos de este tipo son tipicos en estudios de crecimiento, por ejemplo, ver crecimiento de arboles de Nothofagus obliqua en Salas and Garcı́a (2006).
Es siempre necesario conocer la estructura de los datos y en caso de que existan factores, cuantos niveles hay. Esto se puede realizar mediante
str(df)
'data.frame': 35 obs. of 6 variables:
$ arbol.no: int 1 1 1 1 1 1 1 2 2 2 ...
$ tiempo : int 118 484 664 1004 1231 1372 1582 118 484 664 ...
$ peri : int 30 58 87 115 120 142 145 33 69 111 ...
$ dap : num 9.55 18.46 27.69 36.61 38.2 ...
$ sitio : chr "Northern site" "Northern site" "Northern site" "Northern site" ...
$ especie : chr "Radiata pine" "Radiata pine" "Radiata pine" "Radiata pine" ...
unique(df$sitio)
[1] "Northern site" "Southern site"
unique(df$especie)
[1] "Radiata pine" "Beech" "Douglas-fir"
source("timeSerPlot.R")
timeSerPlot(df, y="dap", x="tiempo", obs.unit = "arbol.no")
timeSerPlot(df, y="dap", x="tiempo", obs.unit = "arbol.no",
factor1="sitio")
timeSerPlot(df, y="dap", x="tiempo", obs.unit = "arbol.no",
factor1="sitio", factor2= "especie")
Tambien puede invertir la posicion de los factores, es decir, dejar el factor “especie” como panel principal, y al factor “sitio” con una leyenda diferente.
timeSerPlot(df, y="dap", x="tiempo", obs.unit = "arbol.no",
factor2="sitio", factor1= "especie")
timeSerPlot(df, y="dap", x="tiempo", obs.unit = "arbol.no",
factor1="sitio", factor2= "especie",
factor2.col = T, only.lines = T,
xlab = "Tiempo (dias desde germinacion)",
ylab = "Diametro del fuste (cm)")