library(tidyverse)
## ── Attaching packages ─────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4
## ✓ tibble 3.0.3 ✓ dplyr 1.0.2
## ✓ tidyr 1.1.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(visdat)
library(cowplot)
library(ggrepel)
library(mapproj)
## Loading required package: maps
##
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
##
## map
library(ggthemes)
##
## Attaching package: 'ggthemes'
## The following object is masked from 'package:cowplot':
##
## theme_map
library(here)
## here() starts at /cloud/project
library(extrafont)
## Registering fonts with R
library(extrafont)
library(knitr)
library(magick)
## Linking to ImageMagick 6.9.7.4
## Enabled features: fontconfig, freetype, fftw, lcms, pango, x11
## Disabled features: cairo, ghostscript, rsvg, webp
## Using 16 threads
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
library(forcats)
library(ggplot2)
penguins <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-28/penguins.csv')
## Parsed with column specification:
## cols(
## species = col_character(),
## island = col_character(),
## bill_length_mm = col_double(),
## bill_depth_mm = col_double(),
## flipper_length_mm = col_double(),
## body_mass_g = col_double(),
## sex = col_character(),
## year = col_double()
## )
antarctica <- map_data("world", region = "Antarctica")
df_penguinloc <-
tibble(
island = c("Dream", "Biscoe", "Torgersen"),
lat_y = c(-64.7333, -65.4333, -64.7666636),
long_x = c(-64.2333, -65.5000, -64.083333)
)
df_penguinloc
df_penguinloc <- penguins %>%
group_by(island) %>%
summarise(amount = n(), .groups = 'drop') %>%
left_join(df_penguinloc, by = "island")
df_penguinloc
d <- penguins %>% filter(year==2009) %>%
mutate(island = factor(island),
island = factor(island, levels = rev(levels(island)))) %>%
ggplot() +
stat_count(aes(island, fill = species), alpha = 0.8) +
annotate("text", y=3, x= "Torgersen", label= "Torgersen", color = "#1874CD")+
annotate("text", y=3, x= "Dream", label= "Dream", color = "#c02728")+
annotate("text", y=3, x= "Biscoe", label= "Biscoe", color = "#53868B")+
scale_fill_manual(values = c("#66c2a5","#fc8d62","#8da0cb")) +
scale_y_reverse()+
labs(caption = "Source: Gorman, Williams and Fraser, 2014") +
theme_minimal() +
theme(legend.position = c(0.2,0.3),
axis.title = element_blank(),
axis.text.x = element_blank(),
panel.grid = element_blank(),
plot.background = element_rect(fill="#f9f9f9", color = "#f9f9f9"))
d
p <- ggplot(antarctica, aes(long, lat, group = group)) +
geom_polygon(fill = "#506B8E", alpha = .8) +
coord_map("ortho", orientation = c(-90, 0, 0),
xlim = c(-62, -55),
ylim = c(-75, -60)) +
geom_text_repel(df_penguinloc, mapping=aes(long_x, lat_y, label = island),
group=1, color = c("#53868B", "#c02728", "#1874CD"),
box.padding = 0.5,
nudge_y = 1, nudge_x = -2, min.segment.length = 0) +
geom_point(df_penguinloc, mapping=aes(long_x, lat_y,
group = 1,
colour = island),
alpha =.7)+
scale_color_manual(values = c("#53868B", "#c02728", "#1874CD"))+
labs(title = "Penguins in Palmer Archipelago",
subtitle = "Recorded penguins in 2009 and their nesting Islands") +
theme_map() +
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5, size = 20),
plot.subtitle = element_text(hjust = 0.5),
plot.background = element_rect(fill="#f9f9f9", color = "#f9f9f9"))
p
inset <- ggplot(antarctica, aes(long, lat, group = group)) +
geom_polygon(fill = "#506B8E", alpha = .5) +
coord_map("ortho", orientation = c(-90, 0, 0)) +
geom_point(df_penguinloc, mapping=aes(long_x, lat_y,
group = island,
colour = island),
alpha =.5, size = 1)+
annotate("rect", color="black", fill = "transparent",
xmin = -68, xmax = -54,
ymin = -75, ymax = -60)+
labs(title = "Antarctica") +
theme_map() +
theme(legend.position = "none",
panel.grid.major.y = element_line(colour="grey"),
plot.title = element_text(hjust = 0.5),
plot.background = element_rect(fill="#f9f9f9", color = "#f9f9f9"))
inset
a <- ggdraw(p) +
draw_plot(inset, x=.47, y=.38, width=.5, height=.4)
a
p1 <- plot_grid(a,d, ncol = 1, rel_widths = c(4, 2), rel_heights = c(2,1))+
theme(plot.background = element_rect(fill="#f9f9f9")) +
labs(title = "Penguins in Palmer Archipelago")
penguin <-here("/penguin.jfif")
p2 <- ggdraw() +
draw_plot(p1) +
draw_image(penguin, x = 0.24, y = 0.38, hjust = 1, width = 0.20, height = 0.25)
p2
length(penguins$species)
## [1] 344
unique(penguins$species)
## [1] "Adelie" "Gentoo" "Chinstrap"
length(unique(penguins$species))
## [1] 3
filter(penguins, bill_length_mm > 55)
filter(penguins, species == 'Gentoo')
filter(penguins, species == 'Gentoo', bill_length_mm > 55)
filter(penguins, species == 'Gentoo' | bill_length_mm > 55)
colnames(penguins)
## [1] "species" "island" "bill_length_mm"
## [4] "bill_depth_mm" "flipper_length_mm" "body_mass_g"
## [7] "sex" "year"
select(penguins, sex, year, species)
bills <- select(penguins, species, island, bill_length_mm, bill_depth_mm, body_mass_g, sex, year)
colnames(bills)
## [1] "species" "island" "bill_length_mm" "bill_depth_mm"
## [5] "body_mass_g" "sex" "year"
bills <- select(penguins,-flipper_length_mm)
colnames(bills)
## [1] "species" "island" "bill_length_mm" "bill_depth_mm"
## [5] "body_mass_g" "sex" "year"
bills <- select(penguins, island:bill_depth_mm, body_mass_g:year)
colnames(bills)
## [1] "island" "bill_length_mm" "bill_depth_mm" "body_mass_g"
## [5] "sex" "year"
bills_1 <- select(penguins,-flipper_length_mm)
bills_2 <- filter(bills_1, species != "Gentoo")
bills <- penguins %>%
select(-flipper_length_mm) %>%
filter(species != "Gentoo")
penguins %>%
select(-flipper_length_mm) %>%
filter(species != "Gentoo")
penguins %>%
group_by(species) %>%
summarize(bill_length_mean = mean(bill_length_mm))
## `summarise()` ungrouping output (override with `.groups` argument)
penguins %>%
group_by(species) %>%
summarize(bill_length_mean = mean(bill_length_mm, na.rm=TRUE))
## `summarise()` ungrouping output (override with `.groups` argument)
penguins %>%
group_by(species, island) %>%
summarize(bill_length_mean = mean(bill_length_mm, na.rm=TRUE))
## `summarise()` regrouping output by 'species' (override with `.groups` argument)
penguins %>%
group_by(species, island, sex) %>%
summarize(bill_length_mean = mean(bill_length_mm, na.rm=TRUE))
## `summarise()` regrouping output by 'species', 'island' (override with `.groups` argument)
bills %>%
group_by(species) %>%
summarize(across(c(bill_length_mm, bill_depth_mm, body_mass_g),
list(mean = ~mean(.x, na.rm=TRUE))))
## `summarise()` ungrouping output (override with `.groups` argument)
bills %>%
transmute(across(c(bill_length_mm, bill_depth_mm, body_mass_g),
list(big = ~sqrt(.x)))) %>%
head(15)
penguins %>%
filter(year == 2007) %>%
group_by(island) %>%
top_n(n() / 2, body_mass_g)
penguins %>%
filter(year == 2007) %>%
group_by(island) %>%
top_frac(1 / 2, body_mass_g)
penguins %>%
select(-species, -island, -year) %>%
group_by(sex) %>%
tidyr::gather("bill_length_mm", "measurement", -group_cols())
penguins %>%
group_by(species) %>%
filter(body_mass_g < median(body_mass_g)) %>%
group_split()
## <list_of<
## tbl_df<
## species : character
## island : character
## bill_length_mm : double
## bill_depth_mm : double
## flipper_length_mm: double
## body_mass_g : double
## sex : character
## year : double
## >
## >[1]>
## [[1]]
## # A tibble: 32 x 8
## species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g
## <chr> <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Chinst… Dream 46.5 17.9 192 3500
## 2 Chinst… Dream 51.3 19.2 193 3650
## 3 Chinst… Dream 45.4 18.7 188 3525
## 4 Chinst… Dream 46.1 18.2 178 3250
## 5 Chinst… Dream 45.9 17.1 190 3575
## 6 Chinst… Dream 50.3 20 197 3300
## 7 Chinst… Dream 46.4 18.6 190 3450
## 8 Chinst… Dream 42.4 17.3 181 3600
## 9 Chinst… Dream 48.5 17.5 191 3400
## 10 Chinst… Dream 43.2 16.6 187 2900
## # … with 22 more rows, and 2 more variables: sex <chr>, year <dbl>
penguins %>%
group_by(species) %>%
filter(body_mass_g < median(body_mass_g)) %>%
group_map(~.x)
## [[1]]
## # A tibble: 32 x 7
## island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g sex year
## <chr> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
## 1 Dream 46.5 17.9 192 3500 fema… 2007
## 2 Dream 51.3 19.2 193 3650 male 2007
## 3 Dream 45.4 18.7 188 3525 fema… 2007
## 4 Dream 46.1 18.2 178 3250 fema… 2007
## 5 Dream 45.9 17.1 190 3575 fema… 2007
## 6 Dream 50.3 20 197 3300 male 2007
## 7 Dream 46.4 18.6 190 3450 fema… 2007
## 8 Dream 42.4 17.3 181 3600 fema… 2007
## 9 Dream 48.5 17.5 191 3400 male 2007
## 10 Dream 43.2 16.6 187 2900 fema… 2007
## # … with 22 more rows
penguins %>% remove_rownames %>% rownames_to_column(var="names")
penguins <- dplyr::as_data_frame(penguins, rownames = "id")
## Warning: `as_data_frame()` is deprecated as of tibble 2.0.0.
## Please use `as_tibble()` instead.
## The signature and semantics have changed, see `?as_tibble`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
ids <- penguins %>%
unite(col = 'id', 'species', 'island', 'sex', id, sep = '_')
head(ids)
ids %>%
separate(col = id, into = c('species', 'island', 'sex'), sep = '_')
## Warning: Expected 3 pieces. Additional pieces discarded in 344 rows [1, 2, 3, 4,
## 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
long_data <- ids %>%
pivot_longer(cols = c(bill_length_mm, bill_depth_mm),
names_to = "bills",
values_to = "mm")
head(long_data, 10)
long_data %>%
pivot_wider(names_from = bills, values_from = mm)
library(reshape2)
##
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
##
## smiths
melt_data <- ids %>%
melt(id.vars=c('id','year'), variable.name = 'measurements')
melt_data
melt_data %>%
dcast(id + year ~ measurements, value.var = "value")
library(stringr)
word(penguins$species, 1) %>% unique()
## [1] "Adelie" "Gentoo" "Chinstrap"
str_detect(penguins$sex, 'never observed')
## [1] FALSE FALSE FALSE NA FALSE FALSE FALSE FALSE NA NA NA NA
## [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE NA
## [49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [85] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [97] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [109] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [121] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [133] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [145] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [157] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [169] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE NA FALSE
## [181] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [193] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [205] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [217] FALSE FALSE NA FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [229] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [241] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [253] FALSE FALSE FALSE FALSE NA FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [265] FALSE FALSE FALSE FALSE NA FALSE FALSE NA FALSE FALSE FALSE FALSE
## [277] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [289] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [301] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [313] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [325] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [337] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
penguins %>% filter(str_detect(body_mass_g, '375'))
penguins %>% filter(str_detect(flipper_length_mm, '31'))
penguins %>% filter(str_detect(sex, 'male'))
penguins %>% filter(str_detect(sex, 'female'))
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
library(tidyverse)
library(visdat)
library(cowplot)
library(ggrepel)
library(mapproj)
library(ggthemes)
library(here)
library(extrafont)
library(extrafont)
library(knitr)
library(magick)
penguins <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-07-28/penguins.csv')
## Parsed with column specification:
## cols(
## species = col_character(),
## island = col_character(),
## bill_length_mm = col_double(),
## bill_depth_mm = col_double(),
## flipper_length_mm = col_double(),
## body_mass_g = col_double(),
## sex = col_character(),
## year = col_double()
## )
library(palmerpenguins)
##
## Attaching package: 'palmerpenguins'
## The following object is masked _by_ '.GlobalEnv':
##
## penguins
kable(head(penguins, 15), caption = "Penguins data. Source: Gorman, Williams and Fraser, 2014 ")
species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | year |
---|---|---|---|---|---|---|---|
Adelie | Torgersen | 39.1 | 18.7 | 181 | 3750 | male | 2007 |
Adelie | Torgersen | 39.5 | 17.4 | 186 | 3800 | female | 2007 |
Adelie | Torgersen | 40.3 | 18.0 | 195 | 3250 | female | 2007 |
Adelie | Torgersen | NA | NA | NA | NA | NA | 2007 |
Adelie | Torgersen | 36.7 | 19.3 | 193 | 3450 | female | 2007 |
Adelie | Torgersen | 39.3 | 20.6 | 190 | 3650 | male | 2007 |
Adelie | Torgersen | 38.9 | 17.8 | 181 | 3625 | female | 2007 |
Adelie | Torgersen | 39.2 | 19.6 | 195 | 4675 | male | 2007 |
Adelie | Torgersen | 34.1 | 18.1 | 193 | 3475 | NA | 2007 |
Adelie | Torgersen | 42.0 | 20.2 | 190 | 4250 | NA | 2007 |
Adelie | Torgersen | 37.8 | 17.1 | 186 | 3300 | NA | 2007 |
Adelie | Torgersen | 37.8 | 17.3 | 180 | 3700 | NA | 2007 |
Adelie | Torgersen | 41.1 | 17.6 | 182 | 3200 | female | 2007 |
Adelie | Torgersen | 38.6 | 21.2 | 191 | 3800 | male | 2007 |
Adelie | Torgersen | 34.6 | 21.1 | 198 | 4400 | male | 2007 |
str(penguins)
## tibble [344 × 8] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ species : chr [1:344] "Adelie" "Adelie" "Adelie" "Adelie" ...
## $ island : chr [1:344] "Torgersen" "Torgersen" "Torgersen" "Torgersen" ...
## $ bill_length_mm : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
## $ bill_depth_mm : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
## $ flipper_length_mm: num [1:344] 181 186 195 NA 193 190 181 195 193 190 ...
## $ body_mass_g : num [1:344] 3750 3800 3250 NA 3450 ...
## $ sex : chr [1:344] "male" "female" "female" NA ...
## $ year : num [1:344] 2007 2007 2007 2007 2007 ...
## - attr(*, "spec")=
## .. cols(
## .. species = col_character(),
## .. island = col_character(),
## .. bill_length_mm = col_double(),
## .. bill_depth_mm = col_double(),
## .. flipper_length_mm = col_double(),
## .. body_mass_g = col_double(),
## .. sex = col_character(),
## .. year = col_double()
## .. )
str(penguins %>% group_by(year))
## tibble [344 × 8] (S3: grouped_df/tbl_df/tbl/data.frame)
## $ species : chr [1:344] "Adelie" "Adelie" "Adelie" "Adelie" ...
## $ island : chr [1:344] "Torgersen" "Torgersen" "Torgersen" "Torgersen" ...
## $ bill_length_mm : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
## $ bill_depth_mm : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
## $ flipper_length_mm: num [1:344] 181 186 195 NA 193 190 181 195 193 190 ...
## $ body_mass_g : num [1:344] 3750 3800 3250 NA 3450 ...
## $ sex : chr [1:344] "male" "female" "female" NA ...
## $ year : num [1:344] 2007 2007 2007 2007 2007 ...
## - attr(*, "spec")=
## .. cols(
## .. species = col_character(),
## .. island = col_character(),
## .. bill_length_mm = col_double(),
## .. bill_depth_mm = col_double(),
## .. flipper_length_mm = col_double(),
## .. body_mass_g = col_double(),
## .. sex = col_character(),
## .. year = col_double()
## .. )
## - attr(*, "groups")= tibble [3 × 2] (S3: tbl_df/tbl/data.frame)
## ..$ year : num [1:3] 2007 2008 2009
## ..$ .rows: list<int> [1:3]
## .. ..$ : int [1:110] 1 2 3 4 5 6 7 8 9 10 ...
## .. ..$ : int [1:114] 51 52 53 54 55 56 57 58 59 60 ...
## .. ..$ : int [1:120] 101 102 103 104 105 106 107 108 109 110 ...
## .. ..@ ptype: int(0)
## ..- attr(*, ".drop")= logi TRUE
glimpse(penguins)
## Rows: 344
## Columns: 8
## $ species <chr> "Adelie", "Adelie", "Adelie", "Adelie", "Adelie", "…
## $ island <chr> "Torgersen", "Torgersen", "Torgersen", "Torgersen",…
## $ bill_length_mm <dbl> 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1,…
## $ bill_depth_mm <dbl> 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1,…
## $ flipper_length_mm <dbl> 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 18…
## $ body_mass_g <dbl> 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475,…
## $ sex <chr> "male", "female", "female", NA, "female", "male", "…
## $ year <dbl> 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 200…
penguins %>%
#group_by(species) %>%
select(everything()) %>%
summarise_all(funs(sum(is.na(.)))) %>%
pivot_longer(cols = 1:7, names_to = 'columns', values_to = 'NA_count') %>%
arrange(desc(NA_count)) %>%
ggplot(aes(y = columns, x = NA_count)) + geom_col(fill = 'darkorange') +
geom_label(aes(label = NA_count)) +
# scale_fill_manual(values = c("darkorange","purple","cyan4")) +
theme_minimal() +
labs(title = 'Penguins - NA Count')
## Warning: `funs()` is deprecated as of dplyr 0.8.0.
## Please use a list of either functions or lambdas:
##
## # Simple named list:
## list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`:
## tibble::lst(mean, median)
##
## # Using lambdas
## list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
library(GGally)
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
penguins %>%
select_if(is.numeric) %>%
select(-year) %>%
drop_na() %>%
ggpairs()
plot(penguins[,-1])
penguins %>%
count(species) %>%
ggplot() + geom_col(aes(x = species, y = n, fill = species)) +
geom_label(aes(x = species, y = n, label = n)) +
scale_fill_manual(values = c("darkorange","purple","cyan4")) +
theme_minimal() +
labs(title = 'Penguins Species & Count')
penguins %>%
drop_na() %>%
count(sex, species) %>%
ggplot() + geom_col(aes(x = species, y = n, fill = species)) +
geom_label(aes(x = species, y = n, label = n)) +
scale_fill_manual(values = c("darkorange","purple","cyan4")) +
facet_wrap(~sex) +
theme_minimal() +
labs(title = 'Penguins Species ~ Gender')
penguins %>%
select_if(is.numeric) %>%
select(-year) %>%
drop_na() %>%
cor()
## bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
## bill_length_mm 1.0000000 -0.2350529 0.6561813 0.5951098
## bill_depth_mm -0.2350529 1.0000000 -0.5838512 -0.4719156
## flipper_length_mm 0.6561813 -0.5838512 1.0000000 0.8712018
## body_mass_g 0.5951098 -0.4719156 0.8712018 1.0000000
ggplot(data = penguins, aes(x = flipper_length_mm, y = body_mass_g)) +
geom_point(aes(color = species, shape = sex), size = 3, alpha = 0.8) +
theme_minimal() +
scale_color_manual(values = c("darkorange","purple","cyan4")) +
labs(title = "Penguin size, Palmer Station LTER",
subtitle = "Flipper length and body mass for Adelie, Chinstrap and Gentoo Penguins",
x = "Flipper length (mm)",
y = "Body mass (g)",
color = "Penguin species",
shape = "Penguin sex") +
theme_minimal()
## Warning: Removed 11 rows containing missing values (geom_point).
ggplot(data = penguins, aes(x = flipper_length_mm, y = body_mass_g)) +
geom_point(aes(color = island, shape = species), size = 3, alpha = 0.8) +
theme_minimal() +
scale_color_manual(values = c("darkorange","purple","cyan4")) +
labs(title = "Penguin size, Palmer Station LTER",
subtitle = "Flipper length and body mass for each island",
x = "Flipper length (mm)",
y = "Body mass (g)",
color = "Penguin island",
shape = "Penguin species") +
theme_minimal()
## Warning: Removed 2 rows containing missing values (geom_point).