library (ggplot2)
library (dplyr)
library (skimr)
algunos comandos utiles para explorar la data rectangular o dataframe
dplyr::glimpse(mpg)
Observations: 234
Variables: 11
$ manufacturer <chr> "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi", "audi", "...
$ model <chr> "a4", "a4", "a4", "a4", "a4", "a4", "a4", "a4 quattro", "a4 quattro", "a4...
$ displ <dbl> 1.8, 1.8, 2.0, 2.0, 2.8, 2.8, 3.1, 1.8, 1.8, 2.0, 2.0, 2.8, 2.8, 3.1, 3.1...
$ year <int> 1999, 1999, 2008, 2008, 1999, 1999, 2008, 1999, 1999, 2008, 2008, 1999, 1...
$ cyl <int> 4, 4, 4, 4, 6, 6, 6, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8...
$ trans <chr> "auto(l5)", "manual(m5)", "manual(m6)", "auto(av)", "auto(l5)", "manual(m...
$ drv <chr> "f", "f", "f", "f", "f", "f", "f", "4", "4", "4", "4", "4", "4", "4", "4"...
$ cty <int> 18, 21, 20, 21, 16, 18, 18, 18, 16, 20, 19, 15, 17, 17, 15, 15, 17, 16, 1...
$ hwy <int> 29, 29, 31, 30, 26, 26, 27, 26, 25, 28, 27, 25, 25, 25, 25, 24, 25, 23, 2...
$ fl <chr> "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p"...
$ class <chr> "compact", "compact", "compact", "compact", "compact", "compact", "compac...
nombre + () = función glimpse nos da un resumen de las variables que tenemos
skim(mpg)
Skim summary statistics
n obs: 234
n variables: 11
-- Variable type:character -----------------------------------------------------
variable missing complete n min max empty n_unique
class 0 234 234 3 10 0 7
drv 0 234 234 1 1 0 3
fl 0 234 234 1 1 0 5
manufacturer 0 234 234 4 10 0 15
model 0 234 234 2 22 0 38
trans 0 234 234 8 10 0 10
-- Variable type:integer -------------------------------------------------------
variable missing complete n mean sd p0 p25 p50 p75 p100 hist
cty 0 234 234 16.86 4.26 9 14 17 19 35 <U+2585><U+2587><U+2587><U+2587><U+2581><U+2581><U+2581><U+2581>
cyl 0 234 234 5.89 1.61 4 4 6 8 8 <U+2587><U+2581><U+2581><U+2587><U+2581><U+2581><U+2581><U+2587>
hwy 0 234 234 23.44 5.95 12 18 24 27 44 <U+2583><U+2587><U+2583><U+2587><U+2585><U+2581><U+2581><U+2581>
year 0 234 234 2003.5 4.51 1999 1999 2003.5 2008 2008 <U+2587><U+2581><U+2581><U+2581><U+2581><U+2581><U+2581><U+2587>
-- Variable type:numeric -------------------------------------------------------
variable missing complete n mean sd p0 p25 p50 p75 p100 hist
displ 0 234 234 3.47 1.29 1.6 2.4 3.3 4.6 7 <U+2587><U+2587><U+2585><U+2585><U+2585><U+2583><U+2582><U+2581>
ggplot() +
geom_point (data = mpg, mapping = aes(x = displ, y = hwy, colour = class, shape = drv))
ggplot(mpg) +
geom_point(aes(x = displ, y = hwy, colour = class)) +
facet_wrap(~drv)
ggplot(data= mpg) +
geom_line(mapping = aes(x = displ, y = hwy))
ggplot(data = mpg) +
geom_bar(aes(x = drv))
data_autos_resumida <- tribble(
~ tipo_traccion, ~num_obs,
"4" , 104,
"f" , 102,
"r" , 25
)
data_autos_resumida
ggplot(data = data_autos_resumida) +
geom_bar(mapping = aes(x = tipo_traccion, y = num_obs),
stat = "identity")
ggplot(mpg) +
geom_smooth(mapping = aes(x = displ, y = hwy))
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy), colour = "turquoise") +
geom_point(mapping = aes(x = displ, y = hwy),
data = data.frame(displ = 4, hwy = 40),
colour = "pink",
size = 4)
library(gapminder)
gapminder
library(dplyr)
filter(gapminder, continent == "Oceania")
datos_oceania <- filter(gapminder, continent == "Oceania")
datos_oceania
glimpse(datos_oceania)
Observations: 24
Variables: 6
$ country <fct> Australia, Australia, Australia, Australia, Australia, Australia, Australi...
$ continent <fct> Oceania, Oceania, Oceania, Oceania, Oceania, Oceania, Oceania, Oceania, Oc...
$ year <int> 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, 2002, 2007, 19...
$ lifeExp <dbl> 69.120, 70.330, 70.930, 71.100, 71.930, 73.490, 74.740, 76.320, 77.560, 78...
$ pop <int> 8691212, 9712569, 10794968, 11872264, 13177000, 14074100, 15184200, 162572...
$ gdpPercap <dbl> 10039.60, 10949.65, 12217.23, 14526.12, 16788.63, 18334.20, 19477.01, 2188...
ggplot(datos_oceania) +
geom_point(mapping = aes(x = gdpPercap, y = lifeExp, size = pop))