install.packages("ggplot2")
install.packages("dplyr")
install.packages("gapminder")
library(ggplot2)
library(gapminder)
install.packages("titanic")
library(ggplot2)
library(dplyr)
library(titanic)
library(dplyr)
# Unir las dos tablas por filas con información de los pasajeros del
# titanic que vienen en el paquete titanic: titanic_train y titanic_test
df <- dplyr::bind_rows(titanic::titanic_train,
titanic::titanic_test)
# Ver que contiene la data, un breve resumen con glimpse():
glimpse(df)
Observations: 1,309
Variables: 12
$ PassengerId <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14...
$ Survived <int> 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, ...
$ Pclass <int> 3, 1, 3, 1, 3, 3, 1, 3, 3, 2, 3, 1, 3, 3, 3, ...
$ Name <chr> "Braund, Mr. Owen Harris", "Cumings, Mrs. Joh...
$ Sex <chr> "male", "female", "female", "female", "male",...
$ Age <dbl> 22, 38, 26, 35, 35, NA, 54, 2, 27, 14, 4, 58,...
$ SibSp <int> 1, 1, 0, 1, 0, 0, 0, 3, 0, 1, 1, 0, 0, 1, 0, ...
$ Parch <int> 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 0, 0, 5, 0, ...
$ Ticket <chr> "A/5 21171", "PC 17599", "STON/O2. 3101282", ...
$ Fare <dbl> 7.2500, 71.2833, 7.9250, 53.1000, 8.0500, 8.4...
$ Cabin <chr> "", "C85", "", "C123", "", "", "E46", "", "",...
$ Embarked <chr> "S", "C", "S", "S", "S", "Q", "S", "S", "S", ...
?titanic::titanic_train
ggplot(data = df) +
geom_bar(mapping = aes(x = Sex), fill = "steelblue", colour = "black") +
ggtitle("Para observar la variación de una variable categórica: geom_bar.")
ggplot(data = df) +
geom_histogram(mapping = aes(x = Fare, fill = Cabin),
colour = "black") +
scale_fill_viridis_d() +
facet_wrap(~ Cabin)
ggplot(data = df) +
geom_bar(mapping = aes(x = Age), fill = "steelblue", colour = "red") +
ggtitle("Gráfico acumulado de personas por edad")
pendejetes <- dplyr::filter(df, Age < 18)
ggplot(data = df, mapping = geom_area()
ggplot(data = pendejetes) +
geom_point(mapping = aes(x = Age, y = Survived, colour = Age)) +
ggtitle("Niños sobrevivientes y muertos por edad")
ggplot(data = pendejetes) +
geom_bar(mapping = aes(x = Sex), fill = "red", colour = "blue") +
ggtitle("Cantidad de niñas y niños a bordo")
ggplot(data = df) +
geom_bar(mapping = aes(x = Age), fill = "steelblue", colour = "red") +
ggtitle("Gráfico acumulado de personas por edad")
df <- dplyr::bind_rows(titanic::titanic_train, titanic::titanic_test)
filter(df, Survived == "Female")
Sobrevivientes_mujeres <- dplyr::filter(df, Survived, Sex == "female")
Sobrevivientes_hombres <- dplyr::filter(df, Survived, Sex == "male")
ggplot(pendejetes) +
geom_point(aes(x = Pclass, y = Age, Size = Survived)) +
facet_wrap(~ Sex)
Ignoring unknown aesthetics: Size
SobrHM <- dplyr::bind_rows(df::Sobrevivientes_hombres, df::Sobrevivientes_mujeres)
ggplot(pendejetes) +
geom_point(aes(x = Pclass, y = Age, size = Survived, color = Survived, line = Age)) +
facet_wrap(~ Sex) +
ggtitle("Menores sobrevivientes por clase, edad y sexo biológico")
Ignoring unknown aesthetics: line
ggplot(df) +
geom_point(aes(x = Age, y = Pclass, size = Survived)) +
facet_wrap(~ Sex)
ggplot(df) +
geom_freqpoly(mapping = aes (x = Age, y = ..density.., colour = factor(Pclass)))
ggplot(data = df) + geom_freqpoly(mapping = aes(x = Fare, y = ..density.., colour = factor(Pclass),), binwidth = 10, size = 0.8) +