Buenas. Alguien sabe como representar juntos , de forma fácil, los boxplot de todas las columnas de un data.frame. A mí lo único que se me ha ocurrido es unir las columnas en un vector numérico y crear un factor que me diga a que columna pertenece cada uno . ¿hay alguna forma más fácil? indice <- rep(1:ncol(datos),each=nrow(datos)) indice <- factor(indice) levels(indice) <- colnames(datos) unido <- datos[,1] for (i in 2:ncol(datos)){ unido <- c(unido,datos[,i]) } png(file="boxplot.png") boxplot(unido~indice) dev.off() Saludos.
Hola, creo que simplemente usando: boxplot(nombre.del.data.frame) por ejemplo: aa <- as.data.frame(matrix(runif(100,0,10),nrow=20)) boxplot(aa) Un saludo, Jorge El Tuesday 21 February 2012 13:24:32 José Luis Cañadas escribió:> Buenas. > > Alguien sabe como representar juntos , de forma fácil, los boxplot de > todas las columnas de un data.frame. A mí lo único que se me ha ocurrido > es unir las columnas en un vector numérico y crear un factor que me diga > a que columna pertenece cada uno . ¿hay alguna forma más fácil? > > > indice <- rep(1:ncol(datos),each=nrow(datos)) > indice <- factor(indice) > levels(indice) <- colnames(datos) > unido <- datos[,1] > for (i in 2:ncol(datos)){ > unido <- c(unido,datos[,i]) > } > png(file="boxplot.png") > boxplot(unido~indice) > dev.off() > > Saludos. > > _______________________________________________ > R-help-es mailing list > R-help-es en r-project.org > https://stat.ethz.ch/mailman/listinfo/r-help-es
jajaja. Y yo complicándome , con lo fácil que era. Gracias. El 21/02/12 13:45, Jorge Virto escribió:> Hola, > > creo que simplemente usando: > > boxplot(nombre.del.data.frame) > > por ejemplo: > > aa <- as.data.frame(matrix(runif(100,0,10),nrow=20)) > boxplot(aa) > > Un saludo, > > Jorge > > > El Tuesday 21 February 2012 13:24:32 José Luis Cañadas escribió: >> Buenas. >> >> Alguien sabe como representar juntos , de forma fácil, los boxplot de >> todas las columnas de un data.frame. A mí lo único que se me ha ocurrido >> es unir las columnas en un vector numérico y crear un factor que me diga >> a que columna pertenece cada uno . ¿hay alguna forma más fácil? >> >> >> indice <- rep(1:ncol(datos),each=nrow(datos)) >> indice <- factor(indice) >> levels(indice) <- colnames(datos) >> unido <- datos[,1] >> for (i in 2:ncol(datos)){ >> unido <- c(unido,datos[,i]) >> } >> png(file="boxplot.png") >> boxplot(unido~indice) >> dev.off() >> >> Saludos. >> >> _______________________________________________ >> R-help-es mailing list >> R-help-es en r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-help-es > _______________________________________________ > R-help-es mailing list > R-help-es en r-project.org > https://stat.ethz.ch/mailman/listinfo/r-help-es
Además, la función melt del paquete reshape habría puesto en columnas las variables del dataframe (formato largo que dicen en la documentación) en un solo paso, creando el factor de los nombres de las columnas originales por el camino, por si quieres hacer otras cosas o usarla con ggplot2. Prueba: library(reshape) aa <- as.data.frame(matrix(runif(100,0,10),nrow=20)) melt(aa) Un saludo Gregorio R. Serrano El 21 de febrero de 2012 13:57, José Luis Cañadas <canadasreche@gmail.com>escribió:> jajaja. Y yo complicándome , con lo fácil que era. > > Gracias. > > El 21/02/12 13:45, Jorge Virto escribió: > > Hola, > > > > creo que simplemente usando: > > > > boxplot(nombre.del.data.frame) > > > > por ejemplo: > > > > aa <- as.data.frame(matrix(runif(100,0,10),nrow=20)) > > boxplot(aa) > > > > Un saludo, > > > > Jorge > > > > > > El Tuesday 21 February 2012 13:24:32 José Luis Cañadas escribió: > >> Buenas. > >> > >> Alguien sabe como representar juntos , de forma fácil, los boxplot de > >> todas las columnas de un data.frame. A mí lo único que se me ha ocurrido > >> es unir las columnas en un vector numérico y crear un factor que me diga > >> a que columna pertenece cada uno . ¿hay alguna forma más fácil? > >> > >> > >> indice <- rep(1:ncol(datos),each=nrow(datos)) > >> indice <- factor(indice) > >> levels(indice) <- colnames(datos) > >> unido <- datos[,1] > >> for (i in 2:ncol(datos)){ > >> unido <- c(unido,datos[,i]) > >> } > >> png(file="boxplot.png") > >> boxplot(unido~indice) > >> dev.off() > >> > >> Saludos. > >> > >> _______________________________________________ > >> R-help-es mailing list > >> R-help-es@r-project.org > >> https://stat.ethz.ch/mailman/listinfo/r-help-es > > _______________________________________________ > > R-help-es mailing list > > R-help-es@r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-help-es > > _______________________________________________ > R-help-es mailing list > R-help-es@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-help-es >-- Dr. Gregorio R. Serrano Dpto. Economía Cuantitativa (UCM) Voz:+34 91394 2361 Twitter: @grserrano_ http://www.grserrano.es [[alternative HTML version deleted]]