practica3

ahushudeduwehduweduweduweidjeijdweijdwejdipwejdiwejdlñwejdpowejdkojwpowejkeeee https://rmarkdown.rstudio.com/.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(haven)
## Warning: package 'haven' was built under R version 4.6.2
lapop23 <- read_sav("C:/Users/usuariosalas/Downloads/lapop23 (2).sav")
View(lapop23)


library(dplyr)
## 
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
### Punto 1

df <- lapop23 %>%
  select(q2, vic1ext, aoj11) %>%
  filter(
    q2 >= 18 & q2 <= 87,
    vic1ext >= 1 & vic1ext <= 2,
    aoj11 >= 1 & aoj11 <= 4
  )

glimpse(df)
## Rows: 1,492
## Columns: 3
## $ q2      <dbl+lbl> 24, 43, 60, 50, 58, 26, 30, 27, 48, 47, 45, 18, 82, 47, 73…
## $ vic1ext <dbl+lbl> 1, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 2…
## $ aoj11   <dbl+lbl> 4, 4, 2, 2, 1, 3, 1, 3, 3, 1, 2, 2, 4, 4, 2, 2, 4, 2, 3, 3…
library(ggpattern)
## Warning: package 'ggpattern' was built under R version 4.6.2
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.6.2
library(hrbrthemes)
## Warning: package 'hrbrthemes' was built under R version 4.6.2
# 1. Crear la tabla de frecuencias absolutas
tabla_seguridad <- as.data.frame(table(df$aoj11))
colnames(tabla_seguridad) <- c("Seguridad", "Frecuencia")
# 2. Elaborar el gráfico de barras con texturas

ggplot(tabla_seguridad, aes(x=Seguridad, y=Frecuencia)) +
  geom_col_pattern(
    aes(pattern=Seguridad,
        pattern_angle=Seguridad,
        pattern_spacing=Seguridad
    ), 
    fill            = 'white',
    colour          = 'black', 
    pattern_density = 0.5, 
    pattern_fill    = 'black',
    pattern_colour  = 'darkgrey'
  ) +
  theme_bw()

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.