library(ggplot2)
library(dplyr)
library(titanic)Bind_rows juntar tablas por fila glimpse es una foto global de los datos
df <- dplyr::bind_rows(titanic::titanic_train)
(titanic::titanic_test)glimpse(df)Observations: 891
Variables: 12
$ PassengerId <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,...
$ Survived <int> 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0,...
$ Pclass <int> 3, 1, 3, 1, 3, 3, 1, 3, 3, 2, 3, 1, 3, 3, 3, 2, 3, 2, 3, 3, 2, 2, 3, 1, 3,...
$ Name <chr> "Braund, Mr. Owen Harris", "Cumings, Mrs. John Bradley (Florence Briggs Th...
$ Sex <chr> "male", "female", "female", "female", "male", "male", "male", "male", "fem...
$ Age <dbl> 22, 38, 26, 35, 35, NA, 54, 2, 27, 14, 4, 58, 20, 39, 14, 55, 2, NA, 31, N...
$ SibSp <int> 1, 1, 0, 1, 0, 0, 0, 3, 0, 1, 1, 0, 0, 1, 0, 0, 4, 0, 1, 0, 0, 0, 0, 0, 3,...
$ Parch <int> 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 1, 0, 0, 5, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,...
$ Ticket <chr> "A/5 21171", "PC 17599", "STON/O2. 3101282", "113803", "373450", "330877",...
$ Fare <dbl> 7.2500, 71.2833, 7.9250, 53.1000, 8.0500, 8.4583, 51.8625, 21.0750, 11.133...
$ Cabin <chr> "", "C85", "", "C123", "", "", "E46", "", "", "", "G6", "C103", "", "", ""...
$ Embarked <chr> "S", "C", "S", "S", "S", "Q", "S", "S", "S", "C", "S", "S", "S", "S", "S",...
ggplot(data = df) +
geom_bar(mapping = aes(x = Sex), fill = "hotpink", colour = "white" ) +
theme_bw() +
ggtitle("Para obtener la viariación de una variable categórica: geom_bar")count(df, Sex)Control shit m = %>%
df %>%
select(Fare)ggplot(data = df) +
geom_point(mapping = aes(x = Fare, y = 0), color = "hotpink") +
theme_bw()NAcount(df, Fare)df %>%
count(Fare) %>%
ggplot() +
geom_point(mapping = aes(x = Fare, y = 0, size = n),
alpha = 1 / 5,
shape = 21,
fill = "hotpink",
colour = "purple") +
theme_bw()df %>%
select(Fare) %>%
mutate(intervalos = cut_width(Fare, 10))ggplot(data = df) +
geom_histogram(mapping = aes (x = Fare), binwidth = 10, fill = "hotpink", colour = "mediumblue") +
theme_bw() +
ggtitle("Para observar la variación de una variable continua: geom_histogram")ggplot(data = df) +
geom_histogram(mapping = aes(x = Fare, fill = Sex),
colour = "black") +
scale_fill_viridis_d() +
facet_wrap(~)Error: unexpected ')' in:
" scale_fill_viridis_d() +
facet_wrap(~)"
ggplot(data = df) +
geom_freqpoly(mapping = aes(x = Fare, colour = factor (Pclass)),
binwidth = 10,
size = 0.8) +
theme_bw() +
ggtitle ("Para comparar distintas distribuciones: geom_freqpoly")df %>%
count(Pclass)