load( "saeraq.RData" )
Sin pretensión de ser exhaustivos realizamos algunos gráficos. En esta parte del análisis de un cuestionario estos deberán de ser ad hoc y la verdad no hay mucha automatización posible más allá de emplear librerías convenientes en cada caso.
ggplot2
Se realizan gráficos con el paquete ggplot2
(Wickham (2009)). Para la manipulación de datos previa se utilizan los paquetes dplyr
(Wickham and Francois (2016)) y tidyr
(Wickham (2016)).
ingresos
# library( ggplot2 )
ggplot( df, aes( x = nivelIngles, y = ingresos, colour = sexo ) ) +
geom_boxplot() +
facet_grid( origen ~ . )
# library( dplyr )
mediasNivelIngles <- df %>%
select( origen, nivelIngles, sexo, ingresos ) %>%
group_by( origen, nivelIngles, sexo ) %>%
summarise( ingresos = mean( ingresos ) )
ggplot( mediasNivelIngles, aes( x = nivelIngles, y = ingresos, group = sexo, colour = sexo ) ) +
geom_point() +
geom_line() +
facet_grid( . ~ origen ) +
theme_bw() +
theme( axis.text.x = element_text( angle = 90, hjust = 1 ) )
ggplot( df, aes( x = Q01, fill = sexo ) ) +
geom_bar( position = "dodge" ) +
theme_minimal()
# library( tidyr )
df %>%
select( sexo, Q01:Q23 ) %>%
gather( "pregunta", "valor", Q01:Q23 ) %>%
ggplot( aes( x = valor, fill = sexo ) ) +
geom_bar( position = "dodge" ) +
facet_wrap( ~ pregunta ) +
theme( axis.text.x = element_text( angle = 90, hjust = 1 ) )
Wickham, Hadley. 2009. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. http://ggplot2.org.
———. 2016. tidyr: Easily Tidy Data with spread() and gather() Functions. http://CRAN.R-project.org/package=tidyr.
Wickham, Hadley, and Romain Francois. 2016. Dplyr: A Grammar of Data Manipulation. https://CRAN.R-project.org/package=dplyr.
Xie, Yihui. 2015. Dynamic Documents with R and Knitr. Vol. 29. CRC Press.
Servicio de Apoyo Estadístico; alvarohv@um.es, elvira@um.es, antoniojose.peran@um.es, anabelen.marin4@um.es, amaurandi@um.es↩
doc:T3_graficos.Rmd↩