#knitr::opts_chunk$set(echo = TRUE)
# Cargar las bibliotecas necesarias
library(openxlsx)
## Warning: package 'openxlsx' was built under R version 4.3.2
library(readxl)
library(readr)
## Warning: package 'readr' was built under R version 4.3.2
# Establecer el directorio de trabajo
setwd("C:/Users/81060606/Documents/Scripts")
# Establecer el directorio de trabajo
setwd("C:/Users/81060606/Documents/Scripts")
# Leer el archivo CSV con la ruta completa
The_avengers <- readr::read_csv("C:/Users/81060606/Documents/Scripts/The avengers.csv")
## Rows: 173 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (8): Name, Gender, Full/Reserve Avengers Intro, Death1, Return1, Death2,...
## dbl (3): Appearances, Year, Alive
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Los Avengers (también conocidos como “Los Vengadores” en algunos países de habla hispana) son un equipo ficticio de superhéroes que aparece en los cómics publicados por Marvel Comics. El equipo fue creado por el escritor Stan Lee y el dibujante Jack Kirby, y su primera aparición fue en “The Avengers” #1 en septiembre de 1963.

La premisa básica de los Avengers es reunir a un grupo de superhéroes poderosos para enfrentar amenazas que ningún héroe individual podría manejar por sí mismo. A lo largo de los años, la alineación de los Avengers ha cambiado muchas veces, con diferentes personajes que se unen y se van.

# Load required packages:
library(readxl)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.2
##Avengers script

#library(readr)
library(fdth)
## Warning: package 'fdth' was built under R version 4.3.2
## 
## Attaching package: 'fdth'
## The following objects are masked from 'package:stats':
## 
##     sd, var
library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)

```

Muestra las primeras filas del dataframe para verificar que se haya cargado correctamente

head(The_avengers)

Analyse the structure with class and str command, fix the data types if needed:

class(The_avengers) str(The_avengers) names(The_avengers) <- c(“Name”, “Appearances”, “Gender”, “Full/Reserve Avengers Intro”, “Year”, “Years since joining”, “Death1”, “Return1”)

#—- Exploring the Data —-

Getting the first 10 rows of the dataset:

head(The_avengers, 10)

Getting the last 10 rows of the dataset:

tail(The_avengers)

Crea un dataframe de ejemplo con tus datos

data <- data.frame( Name = c(“Wanda Maximoff”, “T’Challa”, “Steven Rogers”, “Bruce Banner”, “Peter Parker”), Appearances = c(100, 150, 80, 120, 200) )

Crea un gráfico de dispersión

ggplot(data, aes(x = Name, y = Appearances)) + geom_point() + labs(title = “Relación entre Appearances y Name de los Avengers”, x = “Nombre del Avenger”, y = “Número de Apariciones”)

Filtrar las columnas relevantes

selected_avengers <- The_avengers %>% select(Gender)

Crear el gráfico apilado

ggplot(selected_avengers, aes(x = ““, fill = Gender)) + geom_bar() + labs(title =”Distribución de Género de los Avengers”, fill = “Género”) + scale_fill_manual(values = c(“MALE” = “blue”, “FEMALE” = “red”))

Contar cuántos están vivos y cuántos muertos

death_counts <- table(The_avengers$Death1)

Mostrar los resultados

print(death_counts) library(ggplot2)

Crear el gráfico de barras

ggplot(The_avengers, aes(x = Death1, fill = Death1)) + geom_bar() + labs(title = “Distribución de Avengers Vivos y Muertos”, x = “Estado Vital”, fill = “Estado”) + scale_fill_manual(values = c(“YES” = “pink”, “NO” = “green”)) + theme_minimal()