You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
R
55 lines
1.2 KiB
R
library(tidyverse)
|
|
library(palmerpenguins) # install.packages("palmerpenguins")
|
|
library(ggthemes)
|
|
|
|
penguins
|
|
|
|
? penguins
|
|
|
|
# ggplot
|
|
ggplot(data = penguins,
|
|
mapping = aes(x=flipper_len, y=body_mass, colour = species)) +
|
|
geom_point() +
|
|
geom_smooth(method = "lm")
|
|
|
|
# ggplot step 2:
|
|
ggplot(data = penguins,
|
|
mapping = aes(x=flipper_len, y=body_mass)) +
|
|
geom_point(mapping = aes(colour = species, shape = species)) +
|
|
geom_smooth(method = "lm")
|
|
|
|
|
|
# ggplot final step:
|
|
ggplot(
|
|
data = penguins,
|
|
mapping = aes(x = flipper_len, y = body_mass)) +
|
|
geom_point(aes(color = species, shape = species), size = 3.5) +
|
|
geom_smooth(method = "lm") +
|
|
labs(
|
|
title = "Body mass and flipper length",
|
|
subtitle = "Dimensions for Adelie, Chinstrap, and Gentoo Penguins",
|
|
x = "Flipper length [mm]", y = "Body mass [g]",
|
|
color = "Species", shape = "Species") +
|
|
scale_color_colorblind()
|
|
|
|
#-=-=-=-=-=-=-=
|
|
# Categorical variables:
|
|
|
|
# CV step 1:
|
|
ggplot(data = penguins,
|
|
mapping = aes(x=species)) +
|
|
geom_bar()
|
|
|
|
# CV step 2:
|
|
ggplot(data = penguins,
|
|
mapping = aes(x= fct_infreq(species))) +
|
|
geom_bar()
|
|
|
|
#-=-=-=-=-=-=-=
|
|
# Numerical variables:
|
|
|
|
|
|
ggplot(data = penguins,
|
|
mapping = aes(x = body_mass)) +
|
|
geom_histogram(binwidth = 350)
|