R para Usuários de SAS
Melinda Higgins, PhD
Research Professor/Senior Biostatistician Emory University

ggplot2 é um pacote gráfico poderoso para Rggplot vem de "grammar of graphics"ggplot2 usa camadas para construir gráficos# Create plot for x=sex and y=diameter
ggplot(data = abalone, aes(sex, diameter))
ggplot()data = abaloneDefina aes para sex e diameter
Ainda sem objetos gráficos
sexdiameter
# Add boxplot geometric object or geom
ggplot(data = abalone,
aes(sex, diameter)) +
geom_boxplot()
+ adiciona camadageom_boxplot() adicionado
Resultado: série de boxplots
F fêmeas, I jovens e M machos
# Add black white theme
ggplot(data = abalone,
aes(sex, diameter)) +
geom_boxplot() +
theme_bw()
theme_bw()
# Change to geom_violin()
ggplot(data = abalone,
aes(sex, diameter)) +
geom_violin() +
theme_bw()
geom_violin substitui geom_boxplot
# Make histogram of shuckedWeight
ggplot(abalone, aes(shuckedWeight)) +
geom_histogram()
geom_histogram()aes() como shuckedWeight
# Make lines black and fill light blue
ggplot(abalone, aes(shuckedWeight)) +
geom_histogram(color = "black",
fill = "lightblue")
color das bordas das barrasfill das barras()
# Add x, y axis labels and title
ggplot(abalone, aes(shuckedWeight)) +
geom_histogram(color = "black",
fill = "lightblue") +
xlab("Shucked Weight") +
ylab("Frequency Counts") +
ggtitle("Shucked Weights Histogram")
xlab() e ylab() para os eixosggtitle() para o título
# Make scatterplot with geom_point()
ggplot(abalone,
aes(rings, shellWeight)) +
geom_point()
aes precisa de duas variáveisgeom_point() adiciona os pontos
# Add smoothed fit line
ggplot(abalone,
aes(rings, shellWeight)) +
geom_point() +
geom_smooth()
geom_smooth()
# Add panels using facet_wrap()
ggplot(abalone,
aes(rings, shellWeight)) +
geom_point() +
geom_smooth() +
facet_wrap(vars(sex))
facet_wrap()vars(sex) define a variável dos painéis
ggplot2R para Usuários de SAS