O modelo é na seguinte sequência: ggplot(data,aes(x,y,color,shape,fill,etc))+geom + outras camadas...
Sendo o aes - função que faz formato do gráfico
library(ggplot2)
library(tidyverse)
## -- Attaching packages -------------------------------------------------------------- tidyverse 1.3.0 --
## v tibble 2.1.3 v dplyr 0.8.3
## v tidyr 1.0.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## v purrr 0.3.3
## -- Conflicts ----------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
view(iris)
ggplot(iris,aes(Petal.Length))+geom_bar()#gráfico de barra
ggplot(iris,aes(Petal.Length))+geom_histogram() #histograma
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(iris,aes(Petal.Length))+geom_histogram(binwidth=0.1) #Histograma2
ggplot(iris,aes(Petal.Length))+geom_density()#gráfico de densidade (estimativa de densidade de kernel)
ggplot(iris,aes(Petal.Length))+geom_freqpoly(binwidth= 0.4) # poligono de frequência
ggplot(iris,aes(Petal.Length))+geom_dotplot(binwidth = 0.1) #gráfico de pontos
g<- ggplot(iris)
g+ geom_histogram(aes(Petal.Length,fill=Species),binwidth=0.1,alpha=0.3,colour="black")
g+ geom_histogram(aes(Petal.Length,colour=Species),binwidth=0.1,fill="black")
#alpha= transparência
#colour = contorno
g+ geom_density(aes(Petal.Length,fill=Species),alpha=0.3,colour="black")
g+ geom_density(aes(Petal.Length,..count..,fill=Species),alpha=0.5,colour="black")
g+geom_freqpoly(aes(Petal.Length,colour=Species),binwidth=0.1,show.legend = TRUE)
g+ geom_histogram(aes(Petal.Length,fill=Species),binwidth=0.1,alpha=0.3,colour="black")+
geom_density(aes(Petal.Length,0.1*..count..,fill=Species),alpha=0.5,colour="black")
g+ geom_histogram(aes(Petal.Length,fill=Species),binwidth=0.1,alpha=0.3)+
geom_freqpoly(aes(Petal.Length,colour=Species),binwidth=0.1)
g+ geom_dotplot(aes(Petal.Length,fill=Species),binwidth=0.1,alpha=0.3)+
geom_freqpoly(aes(Petal.Length,colour=Species),binwidth=0.1)
Referências
Schmuller, Joseph. Análise Estatística com R - Para leigos - Tradução da 2a edição. Alta Books Editora. 2019.
Oliveira, Paulo; Guerra, Saulo; McDonnell, Robert. Ciência de Dados com R. Introdução.Editora IBPAD. Brasília. 2018. Disponível em: {https://cdr.ibpad.com.br/cdr-intro.pdf}