Variable categórica/discreta: características, algo acotado (edad)
Variable continua: de tiempo, velocidad, notas
group:by –> cambia dominio de acción de los verbos
es útil para comportamiento a nivel de grupos
puede agrupar valores por grupos (paises por continente)
primero hay que crear una tabla.
chile <- asignación de funcion (nombre a la izq)
library(ggplot2)
library(dplyr)
library(titanic)
df <- dplyr::bind_rows(titanic::titanic_train,
titanic_test)
glimpse(df)
Observations: 1,309
Variables: 12
$ PassengerId <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...
$ 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,...
$ 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,...
$ Name <chr> "Braund, Mr. Owen Harris", "Cumings, Mrs. John Bradley (Florence Briggs...
$ Sex <chr> "male", "female", "female", "female", "male", "male", "male", "male", "...
$ Age <dbl> 22, 38, 26, 35, 35, NA, 54, 2, 27, 14, 4, 58, 20, 39, 14, 55, 2, NA, 31...
$ 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,...
$ 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,...
$ Ticket <chr> "A/5 21171", "PC 17599", "STON/O2. 3101282", "113803", "373450", "33087...
$ Fare <dbl> 7.2500, 71.2833, 7.9250, 53.1000, 8.0500, 8.4583, 51.8625, 21.0750, 11....
$ Cabin <chr> "", "C85", "", "C123", "", "", "E46", "", "", "", "G6", "C103", "", "",...
$ Embarked <chr> "S", "C", "S", "S", "S", "Q", "S", "S", "S", "C", "S", "S", "S", "S", "...
ggplot(data = df) +
geom_bar(mapping = aes (x = Sex), fill = "steelblue", colour = "black")+
theme_bw() +
ggtitle("Para observar la variación de una variable categórica: geom_bar")
count (df, Sex)
%>% (ctrl + shif + m)
df %>%
select(Fare)
ggplot (data = df) +
geom_point (mapping = aes (x = Fare, y = 0)) +
theme_bw ()
df %>%
count(Fare) %>%
ggplot () +
geom_point(mapping = aes (x = Fare, y = 0, size = n),
alpha = 1/ 5,
shape = 21,
fill = "red",
colour = "black") +
theme_bw()
MUTATE: crea una variable en base a la data rectángular que tengo.
ggplot(data = df) +
geom_histogram(mapping = aes (x = Fare), binwidth = 10, fill = "orange",
colour = "black") +
theme_bw () +
ggtitle ("Para obrservar la variación de una variable continua")
NA
para bajar y tener más lineas