library(jpeg)
library(png)
library(tibble)
library(tidyverse)
library(palmerpenguins)
library(vtable)
library(ggplot2)
DATA VISULIZATION
LOADING PACKAGES
LOADING PENGUINS DATA
penguins
HISTOGRAM
data("penguins")
%>%
penguins group_by(species) %>%
ggplot(aes(x=bill_length_mm, color=species, fill=species))+
geom_histogram()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_bin()`).
BOXPLOTS
data("penguins")
%>%
penguins group_by(species) %>%
ggplot(aes(x=species,
y=bill_length_mm,
color=species,
fill=species))+
geom_boxplot(alpha=0.5)+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_boxplot()`).
EXERCISE 1
Reproducing a histogram of flipper lenght amoung the species
data("penguins")
%>%
penguins group_by(species) %>%
ggplot(aes(x=flipper_length_mm, color=species, fill=species))+
geom_histogram()
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_bin()`).
EXERCISE 2
Reproducing a boxplot of the flipper length amoung the species
data("penguins")
%>%
penguins group_by(species) %>%
ggplot(aes(x=species,
y=flipper_length_mm,
color=species,
fill=species))+
geom_boxplot(alpha=0.5)+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_boxplot()`).
GEOM BAR
%>%
penguins ggplot(aes(x=species,
color=species,
fill=species))+
geom_bar(alpha=0.5)+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
%>%
penguins ggplot(aes(x=year,
color=species,
fill=species))+
geom_bar()+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
%>%
penguins ggplot(aes(x=island,
color=species,
fill=species))+
geom_bar()+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
GEOM POINT
%>%
penguins ggplot(aes(x=bill_length_mm,
y = bill_depth_mm))+
geom_point()+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
%>%
penguins ggplot(aes(x=bill_length_mm,
y = bill_depth_mm,
color=species,
fill=species))+
geom_point()+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
BOXPLOT
%>%
penguins na.omit() %>%
ggplot(aes(x=sex,
y = body_mass_g,
color=species,
fill=species))+
geom_boxplot(alpha=0.7)+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
%>%
penguins na.omit() %>%
ggplot(aes(x=species,
y = body_mass_g,
color=sex,
fill=sex))+
geom_boxplot(alpha=0.7)+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
EXERCISE 3
Reproducing a boxplot of the bill length amoung the species
data("penguins")
%>%
penguins group_by(species) %>%
ggplot(aes(x=species,
y=bill_length_mm,
color=species,
fill=species))+
geom_boxplot(alpha=0.5)+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
Warning: Removed 2 rows containing non-finite outside the scale range
(`stat_boxplot()`).
EXERCISE 4
Reproducing a boxplot of the flipper length amoung sex between species
%>%
penguins na.omit() %>%
ggplot(aes(x=species,
y = flipper_length_mm,
color=sex,
fill=sex))+
geom_boxplot(alpha=0.7)+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))
GEOM DENSITY
%>%
penguins na.omit() %>%
pivot_longer(bill_length_mm:body_mass_g, names_to = "trait") %>%
ggplot(aes(x=value,
group=species,
fill=species,
color=species))+
geom_density(alpha=0.7)+
facet_grid(~trait, scales = "free_x" )+
theme(axis.text=element_text(size=16),
axis.title=element_text(size=16))+
theme_minimal()