Datos y Paquetes

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.3
library(stringr)

load("genero12.Rda")

Gráficos Univariables

Para variables categóricas: Gráfico de Barras Simple

Barras verticales

tabla.p35r <- as.data.frame(prop.table(table(genero12$P35C))*100)

ggplot(tabla.p35r, aes(x = Var1, y =  Freq)) + geom_bar(stat="identity") + 
  xlab("") + ylab("% de entrevistados") +
  ggtitle("Pensando en las tareas del hogar, ¿quien cree que podría\nrealizar mejor: cuidar a los miembros de la familia\nque están enfermos?, ¿el hombre o la mujer?") +
  theme_bw()

tabla.p51d <- as.data.frame(prop.table(table(genero12$P51D))*100)

ggplot(tabla.p51d, aes(x = Var1, y =  Freq)) + xlab("") +
  ylab("% de entrevistados") +
  geom_bar(stat="identity") + 
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10)) +
  ggtitle("Opinión de acuerdo o en desacuerdo con la siguiente afirmación:\n ''Jamás tendría un amigo homosexual o una amiga lesbiana''") +
  theme_bw()

Barras horizontales

tabla.p29 <- as.data.frame(prop.table(table(genero12$P29))*100)

ggplot(tabla.p29, aes(x = Var1, y =  Freq)) + xlab("") +
  ylab("% de los entrevistados con pareja") +
  geom_bar(stat="identity") + 
  scale_x_discrete(labels = function(x) str_wrap(x, width = 23)) +
  ggtitle("¿Cómo administran Ud. y su pareja los ingresos que perciben?") +
  theme_bw() +
  coord_flip()

Para variables cuantitativas

Histograma

Primero contar con el rango para definir la amplitud de las barras / número de barras

range(genero12$P19A, na.rm=T)
## [1]   0 112

Amplitud 8, 14 barras:

ggplot(genero12, aes(P19A)) + geom_histogram(bins = 14) + xlab("") +
  ylab("No. de entrevistados") + 
  ggtitle("Histograma: Horas semanales dedicadas a labores domésticas") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_bin).

Amplitud 4, 28 barras:

ggplot(genero12, aes(P19A)) + geom_histogram(bins = 28) + xlab("") +
  ylab("No. de entrevistados") + 
  ggtitle("Histograma: Horas semanales dedicadas a labores domésticas") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_bin).

Amplitud 16, 7 barras:

ggplot(genero12, aes(P19A)) + geom_histogram(bins = 7) + xlab("") +
  ylab("No. de entrevistados") + 
  ggtitle("Histograma: Horas semanales dedicadas a labores domésticas") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_bin).

Polígono de frecuencias

ggplot(genero12, aes(P19A)) + geom_freqpoly(bins=14) + xlab("") +
  ylab("No. de entrevistados") + 
  ggtitle("Polígono de frecuencias: Horas semanales dedicadas \na labores domésticas") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_bin).

Gráfico de cajas o BOXPLOT

boxplot(genero12$P2)

boxplot(genero12$P1)

## Ojiva o gráfico de frecuencias acumuladas

ggplot(genero12, aes(P19A)) + geom_step(stat = "ecdf") +
   xlab("Horas") + ylab("Proporción acumulada de casos") +
  ggtitle("Horas semanales dedicadas a labores domésticas") + theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_ecdf).

Gráficos Multivariables

Barras múltiples

tabla.p35r_sex <- as.data.frame(prop.table(table(genero12$P35C, genero12$SEXO),2)*100)
tabla.p35r_sex
##          Var1      Var2       Freq
## 1      Hombre Masculino  2.2071307
## 2       Mujer Masculino 50.9337861
## 3 Ambos igual Masculino 46.0101868
## 4     NS / NR Masculino  0.8488964
## 5      Hombre  Femenino  2.9315961
## 6       Mujer  Femenino 56.6775244
## 7 Ambos igual  Femenino 39.9022801
## 8     NS / NR  Femenino  0.4885993
ggplot(tabla.p35r_sex, aes(x = Var1, y =  Freq, fill=Var2)) + 
  geom_bar(stat="identity", position="dodge") +
  xlab("") + ylab("% de entrevistados") + labs(fill="Sexo") +
  ggtitle("Pensando en las tareas del hogar, ¿quien cree que podría\nrealizar mejor: cuidar a los miembros de la familia\nque están enfermos?, ¿el hombre o la mujer?, \nRespuestas según el sexo del entrevistado") +
  theme_bw()

ggplot(tabla.p35r_sex, aes(x = Var2, y =  Freq, fill=Var1)) + 
  geom_bar(stat="identity") +
  xlab("") + ylab("% de entrevistados") + labs(fill="Sexo") +
  ggtitle("Pensando en las tareas del hogar, ¿quien cree que podría\nrealizar mejor: cuidar a los miembros de la familia\nque están enfermos?, ¿el hombre o la mujer?, \nRespuestas según el sexo del entrevistado") +
  theme_bw()

Barras horizontales

tabla.p29_sex <- as.data.frame(prop.table(table(genero12$P29, genero12$SEXO),2)*100)

ggplot(tabla.p29_sex, aes(x = Var1, y =  Freq, fill=Var2)) + xlab("") +
  ylab("% de los entrevistados con pareja") +
  geom_bar(stat="identity", position = "dodge") + 
  labs(fill="Sexo") +
  scale_x_discrete(labels = function(x) str_wrap(x, width = 23)) +
  ggtitle("¿Cómo administran Ud. y su pareja los ingresos que\n perciben?, respuestas según el sexo del entrevistado") +
  theme_bw() +
  coord_flip()

Histograma múltiple

Primero contar con el rango para definir la amplitud de las barras / número de barras

ggplot(genero12, aes(P19A)) + geom_histogram(bins = 14) + xlab("") + 
  facet_grid(SEXO ~.) +
  ylab("No. de entrevistados") + 
  ggtitle("Histograma: Horas semanales dedicadas a labores domésticas \nsegún sexo del entrevistado") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_bin).

ggplot(genero12, aes(P19A)) + geom_histogram(bins = 14) + xlab("") + 
  facet_grid(NSEGrup ~.) +
  ylab("No. de entrevistados") + 
  ggtitle("Histograma: Horas semanales dedicadas a labores domésticas \nsegún nivel socioeconómico del entrevistado") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_bin).

ggplot(genero12, aes(P19A)) + geom_histogram(bins = 14) + xlab("") + 
  facet_grid(NSEGrup ~ SEXO) +
  ylab("No. de entrevistados") + 
  ggtitle("Histograma: Horas semanales dedicadas a labores domésticas \nsegún sexo y nivel socioeconómico del entrevistado") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_bin).

Polígono de frecuencias

ggplot(genero12, aes(P19A,..density..*1000,colour=SEXO)) + geom_freqpoly(bins=14) +
  xlab("") +  ylab("% de entrevistados") + 
  ggtitle("Polígono de frecuencias: Horas semanales dedicadas \na labores domésticas, según sexo del entrevistado") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_bin).

ggplot(genero12, aes(P19A,..density..*1000,colour=SEXO)) + geom_freqpoly(bins=14) +
  xlab("") +  ylab("% de entrevistados") + 
  ggtitle("Polígono de frecuencias: Horas semanales dedicadas \na labores domésticas, según sexo y nivel socioeconómico del entrevistado") + facet_grid(NSEGrup ~.)
## Warning: Removed 7 rows containing non-finite values (stat_bin).

  theme_bw()
## List of 57
##  $ line                 :List of 6
##   ..$ colour       : chr "black"
##   ..$ size         : num 0.5
##   ..$ linetype     : num 1
##   ..$ lineend      : chr "butt"
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ rect                 :List of 5
##   ..$ fill         : chr "white"
##   ..$ colour       : chr "black"
##   ..$ size         : num 0.5
##   ..$ linetype     : num 1
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ text                 :List of 11
##   ..$ family       : chr ""
##   ..$ face         : chr "plain"
##   ..$ colour       : chr "black"
##   ..$ size         : num 11
##   ..$ hjust        : num 0.5
##   ..$ vjust        : num 0.5
##   ..$ angle        : num 0
##   ..$ lineheight   : num 0.9
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 0 0 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.x         :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 5.5 0 0 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.x.top     :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 0 5.5 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.y         :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : num 90
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 5.5 0 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.y.right   :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : num -90
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 0 0 5.5
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text            :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : chr "grey30"
##   ..$ size         :Class 'rel'  num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x          :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 2.2 0 0 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x.top      :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 0 2.2 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.y          :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 1
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 2.2 0 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.y.right    :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 0 0 2.2
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.ticks           :List of 6
##   ..$ colour       : chr "grey20"
##   ..$ size         : NULL
##   ..$ linetype     : NULL
##   ..$ lineend      : NULL
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ axis.ticks.length    :Class 'unit'  atomic [1:1] 2.75
##   .. ..- attr(*, "valid.unit")= int 8
##   .. ..- attr(*, "unit")= chr "pt"
##  $ axis.line            : list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ axis.line.x          : NULL
##  $ axis.line.y          : NULL
##  $ legend.background    :List of 5
##   ..$ fill         : NULL
##   ..$ colour       : logi NA
##   ..$ size         : NULL
##   ..$ linetype     : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ legend.margin        :Classes 'margin', 'unit'  atomic [1:4] 0.2 0.2 0.2 0.2
##   .. ..- attr(*, "valid.unit")= int 1
##   .. ..- attr(*, "unit")= chr "cm"
##  $ legend.spacing       :Class 'unit'  atomic [1:1] 0.4
##   .. ..- attr(*, "valid.unit")= int 1
##   .. ..- attr(*, "unit")= chr "cm"
##  $ legend.spacing.x     : NULL
##  $ legend.spacing.y     : NULL
##  $ legend.key           :List of 5
##   ..$ fill         : chr "white"
##   ..$ colour       : logi NA
##   ..$ size         : NULL
##   ..$ linetype     : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ legend.key.size      :Class 'unit'  atomic [1:1] 1.2
##   .. ..- attr(*, "valid.unit")= int 3
##   .. ..- attr(*, "unit")= chr "lines"
##  $ legend.key.height    : NULL
##  $ legend.key.width     : NULL
##  $ legend.text          :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         :Class 'rel'  num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.text.align    : NULL
##  $ legend.title         :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : num 0
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ legend.title.align   : NULL
##  $ legend.position      : chr "right"
##  $ legend.direction     : NULL
##  $ legend.justification : chr "center"
##  $ legend.box           : NULL
##  $ legend.box.margin    :Classes 'margin', 'unit'  atomic [1:4] 0 0 0 0
##   .. ..- attr(*, "valid.unit")= int 1
##   .. ..- attr(*, "unit")= chr "cm"
##  $ legend.box.background: list()
##   ..- attr(*, "class")= chr [1:2] "element_blank" "element"
##  $ legend.box.spacing   :Class 'unit'  atomic [1:1] 0.4
##   .. ..- attr(*, "valid.unit")= int 1
##   .. ..- attr(*, "unit")= chr "cm"
##  $ panel.background     :List of 5
##   ..$ fill         : chr "white"
##   ..$ colour       : logi NA
##   ..$ size         : NULL
##   ..$ linetype     : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ panel.border         :List of 5
##   ..$ fill         : logi NA
##   ..$ colour       : chr "grey20"
##   ..$ size         : NULL
##   ..$ linetype     : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ panel.spacing        :Class 'unit'  atomic [1:1] 5.5
##   .. ..- attr(*, "valid.unit")= int 8
##   .. ..- attr(*, "unit")= chr "pt"
##  $ panel.spacing.x      : NULL
##  $ panel.spacing.y      : NULL
##  $ panel.grid.major     :List of 6
##   ..$ colour       : chr "grey92"
##   ..$ size         : NULL
##   ..$ linetype     : NULL
##   ..$ lineend      : NULL
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ panel.grid.minor     :List of 6
##   ..$ colour       : chr "grey92"
##   ..$ size         : num 0.25
##   ..$ linetype     : NULL
##   ..$ lineend      : NULL
##   ..$ arrow        : logi FALSE
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_line" "element"
##  $ panel.ontop          : logi FALSE
##  $ plot.background      :List of 5
##   ..$ fill         : NULL
##   ..$ colour       : chr "white"
##   ..$ size         : NULL
##   ..$ linetype     : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ plot.title           :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         :Class 'rel'  num 1.2
##   ..$ hjust        : num 0
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 0 6.6 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ plot.subtitle        :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         :Class 'rel'  num 0.9
##   ..$ hjust        : num 0
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 0 4.95 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ plot.caption         :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         :Class 'rel'  num 0.9
##   ..$ hjust        : num 1
##   ..$ vjust        : num 1
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 4.95 0 0 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ plot.margin          :Classes 'margin', 'unit'  atomic [1:4] 5.5 5.5 5.5 5.5
##   .. ..- attr(*, "valid.unit")= int 8
##   .. ..- attr(*, "unit")= chr "pt"
##  $ strip.background     :List of 5
##   ..$ fill         : chr "grey85"
##   ..$ colour       : chr "grey20"
##   ..$ size         : NULL
##   ..$ linetype     : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_rect" "element"
##  $ strip.placement      : chr "inside"
##  $ strip.text           :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : chr "grey10"
##   ..$ size         :Class 'rel'  num 0.8
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ strip.text.x         :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 5.5 0 5.5 0
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ strip.text.y         :List of 11
##   ..$ family       : NULL
##   ..$ face         : NULL
##   ..$ colour       : NULL
##   ..$ size         : NULL
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : num -90
##   ..$ lineheight   : NULL
##   ..$ margin       :Classes 'margin', 'unit'  atomic [1:4] 0 5.5 0 5.5
##   .. .. ..- attr(*, "valid.unit")= int 8
##   .. .. ..- attr(*, "unit")= chr "pt"
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi TRUE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ strip.switch.pad.grid:Class 'unit'  atomic [1:1] 0.1
##   .. ..- attr(*, "valid.unit")= int 1
##   .. ..- attr(*, "unit")= chr "cm"
##  $ strip.switch.pad.wrap:Class 'unit'  atomic [1:1] 0.1
##   .. ..- attr(*, "valid.unit")= int 1
##   .. ..- attr(*, "unit")= chr "cm"
##  - attr(*, "class")= chr [1:2] "theme" "gg"
##  - attr(*, "complete")= logi TRUE
##  - attr(*, "validate")= logi TRUE

Boxplot múltiples

ggplot(genero12, aes(x=SEXO, y=P19A)) + geom_boxplot() +
  xlab("") + ylab("Horas") +
  ggtitle("Diagrama de cajas: Horas semanales dedicadas a labores del hogar\nsegún sexo del entrevistado") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_boxplot).

ggplot(genero12, aes(x=SEXO, y=P19A)) + geom_boxplot() +
  xlab("") + ylab("Horas") +
  ggtitle("Diagrama de cajas: Horas semanales dedicadas a labores del hogar\nsegún sexo y nivel socioeconómico del entrevistado") + facet_grid(.~NSEGrup) +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_boxplot).

ggplot(genero12, aes(x=NSEGrup, y=P19A)) + geom_boxplot() +
  xlab("") + ylab("Horas") +
  ggtitle("Diagrama de cajas: Horas semanales dedicadas a labores del hogar\nsegún sexo y nivel socioeconómico del entrevistado") + facet_grid(.~SEXO) +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_boxplot).

ggplot(genero12, aes(x=NSEGrup, y=P19A)) + geom_boxplot(aes(fill=SEXO)) +
  xlab("") + ylab("Horas") +
  ggtitle("Diagrama de cajas: Horas semanales dedicadas a labores del hogar\nsegún sexo y nivel socioeconómico del entrevistado") +
  theme_bw()
## Warning: Removed 7 rows containing non-finite values (stat_boxplot).

Guardar un gráfico en un archivo .PNG

Primero se crea un objeto en R con el gráfico:

grafico1 <- ggplot(tabla.p51d, aes(x = Var1, y =  Freq)) + xlab("") +
  ylab("% de entrevistados") +
  geom_bar(stat="identity") + 
  scale_x_discrete(labels = function(x) str_wrap(x, width = 10)) +
  ggtitle("Opinión de acuerdo o en desacuerdo con la siguiente afirmación:\n ''Jamás tendría un amigo homosexual o una amiga lesbiana''") +
  theme_bw()

grafico1

Luego se graba el gráfico:

png("grafico1.png")
grafico1
dev.off()
## png 
##   2