-
-
Save geofis/ba1bf3d59f8998f6e980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#PAQUETES. NO TODOS ESTOS PAQUETES SUELEN ESTAR DISPONIBLES. VERIFICAR PRIMERO DISPONIBILIDAD, INSTALARLOS EN CASO NECESARIO | |
library(ggplot2) | |
library(dplyr) | |
library(tidyr) | |
#LECTURA DE LOS DATOS | |
d<-read.csv("http://geografiafisica.org/r/gb_geologia.csv", encoding='latin1') | |
d$grupo<-as.factor(d$grupo) | |
#EJERCICIO 1: | |
##EXTRACCIÓN: VERIFICACIÓN | |
umbralexcl<-10 | |
e1<-droplevels(d[d$litologia %in% names(which(table(d$litologia)>umbralexcl)),c('litologia','a','b','c')]) %>% gather(eje,mm,-litologia) %>% select(`tipo litológico`=litologia,eje=eje,mm=mm) | |
##BOXPLOT | |
dev.new() | |
ggplot(e1, aes(x=`tipo litológico`,y=mm,fill=`tipo litológico`)) + geom_boxplot() + facet_wrap(~eje) + scale_x_discrete(labels=substr(names(which(table(d$litologia)>umbralexcl)),0,4)) + labs(title=paste("Tamaños de gravas y bloques (con más de",umbralexcl,"elementos) según tipo litológico para ejes a, b y c"),x="tipo litológico", y="tamaño (en mm)") | |
#EJERCICIO 2: | |
##BOXPLOT | |
dev.new() | |
ggplot(d[,c('grupo','a','b','c')] %>% gather(eje,mm,-grupo), aes(x=grupo,y=mm,fill=grupo)) + geom_boxplot() + facet_wrap(~eje) + scale_x_discrete(labels=sort(substr(unique(d$grupo),0,4))) + labs(title="Tamaños de gravas y bloques según grupos para ejes a, b y c",x="grupos", y="tamaño (en mm)") | |
#EJERCICIO 3: | |
dev.new() | |
ggplot(d[d$grupo %in% c('2','3'),], aes(grupo, fill=litologia)) + geom_bar(position="dodge") + labs(title="Cantidad de gravas y bloques de los grupos 2 y 3",x="grupos", y="cantidad") | |
dev.new() | |
ggplot(d[d$grupo %in% c('2','3'),], aes(grupo, fill=litologia)) + geom_bar() + labs(title="Cantidad de gravas y bloques de los grupos 2 y 3",x="grupos", y="cantidad") | |
dev.new() | |
ggplot(d[d$grupo %in% c('2','3')&d$litologia %in% c('plutónicas','margas/lutitas'),], aes(grupo, fill=litologia)) + geom_bar() + labs(title="Cantidad de rocas plutónicas y margas/lutitas de los grupos 2 y 3",x="grupo", y="cantidad") | |
tc<-table(d$grupo,d$litologia)[c('2','2'),c('plutónicas','margas/lutitas')] | |
chisq.test(tc) | |
#EJERCICIO 4: | |
dev.new() | |
ggplot(d, aes(grupo, fill=litologia)) + geom_bar(position="dodge") + labs(title="Cantidad de gravas y bloques según grupos",x="grupos", y="cantidad") #TODOS LOS GRUPOS DE TRABAJO, TODOS LOS TIPOS DE ROCA | |
dev.new() | |
ggplot(d, aes(grupo, fill=litologia)) + geom_bar() + labs(title="Cantidad de gravas y bloques según grupos",x="grupos", y="cantidad") #TODOS LOS GRUPOS DE TRABAJO, TODOS LOS TIPOS DE ROCA. APILADAS | |
#GENERAL: ALGUNAS TABLAS DE FRECUENCIAS: | |
##TABLA DE CONTINGENCIA DE GRUPOS DE TRABAJO/TIPOS LITOLÓGICOS | |
table(d$grupo,d$litologia) | |
##TABLA DE CONTINGENCIA DE GRUPOS DE TRABAJO/TIPOS LITOLÓGICOS, SÓLO CON TIPOS CON MÁS DE 10 ELEMENTOS | |
table(d$grupo,d$litologia)[,names(which(table(d$litologia)>10))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment