require(tidyverse)
ggplot2::mpg
Atenção - Na linhas de comando múltiplas o “+” deve ser colocado no final da linha de comando. O uso de “Shift+Enter” facilita a separação das linhas de comando para melhor entendimento do script.
plotar variáveis hwy e cty
ggplot(data = mpg) +
geom_point(mapping = aes(x = hwy, y = cty))
ggplot(data = mpg) +
geom_point(mapping = aes(x = hwy, y = cty, color=class))
ggplot(data = mpg) +
geom_point (mapping = aes (x = hwy, y = cty, shape = class))
## Warning: The shape palette can deal with a maximum of 6 discrete values
## because more than 6 becomes difficult to discriminate; you have 7.
## Consider specifying shapes manually if you must have them.
## Warning: Removed 62 rows containing missing values (geom_point).
ggplot(data = mpg) +
geom_point (mapping = aes (x = hwy, y = cty))+
facet_wrap(~class, nrow = 2)
ggplot(data = mpg) +
geom_point (mapping = aes (x = hwy, y = cty))+
facet_wrap(~ class, nrow = 4, ncol = 2)
ggplot(data = mpg) +
geom_point (mapping = aes (x = hwy, y = cty))+
facet_grid(class ~ cyl)
ggplot(data = mpg) +
geom_smooth (mapping = aes (x = cty, y = hwy))
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg) +
geom_smooth (mapping = aes (x = cty, y = hwy, linetype = drv))
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg) +
geom_smooth (mapping = aes (x = hwy, y = displ, color = drv))
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg) +
geom_point(mapping = aes(x = hwy, y = cty)) +
geom_smooth(mapping = aes(x = hwy, y = cty))
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg, mapping = aes(x = hwy, y = cty)) +
geom_point() +
geom_smooth()
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg, mapping = aes(x = hwy, y = cty)) +
geom_point(mapping = aes(color = class)) +
geom_smooth()
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg, mapping = aes(x = hwy, y = cty)) +
geom_point(mapping = aes(color = class)) +
geom_smooth(data = filter(mpg, class == "suv"), se = FALSE)
## `geom_smooth()` using method = 'loess'
ggplot(data = diamonds) +
geom_bar(mapping = aes(x= cut)
)
ggplot(data = diamonds) +
stat_count(mapping = aes(x= cut))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, y = ..prop.., group = 1))
ggplot(data = diamonds) +
geom_col(mapping = aes(x= cut, y = depth))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = cut))
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = clarity))
ggplot(data = diamonds, mapping = aes(x = cut, colour = clarity)) +
geom_bar(fill = NA, position = "identity") # é necessário tornar as barras mais transparente, definindo preenchimento = NA, pois há sobreposição das subcategorias de claridade
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = color), position = "dodge")
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = color), position = "fill")
ggplot(data = mpg, mapping = aes(x = class, y = hwy)) +
geom_boxplot() # Normal
ggplot(data = mpg, mapping = aes(x = class, y = hwy)) +
geom_boxplot() +
coord_flip() # Com troca de eixos