---
title: 第9次课练习
---

```{r}
require(tidyverse)
# require(ggplot2)
require(palmerpenguins)

penguins |>
  select(species, flipper_length_mm, body_mass_g,
    bill_length_mm, sex) |>
  filter(!is.na(sex)) |>
  ggplot(aes(
    x = species,
    y = body_mass_g
    )) +
geom_jitter(colour = "white",
  fill = "gray80", size = 1, shape = 21, width = 0.4) +
geom_violin(fill = "orange", alpha = 0.4) +
stat_summary(fun = mean) +
scale_size_continuous(range = c(.5, 2)) +
# ggsci::scale_fill_d3() +
ylab("Body mass (g)") +
ggtitle("Body mass and flipper length") +
theme(axis.text.x = element_text(angle = 90),
  panel.background = element_rect(fill = NA)
)

ggplot2::last_plot()


ggsave("../img/penguins.pdf", width = 4, heigh = 3)

+
dwfun::theme_sci(5, 5)


p1 <- ggplot(penguins, aes(x = island, fill = species)) +
  geom_bar(position = "fill")
p2 <- ggplot(penguins, aes(x = species, fill = island)) +
  geom_bar(position = "fill")

require(patchwork)
((p1 / p2) | p1)




```



# 消光系数

```{r}
licordata <- readRDS("../data/licordata.RDS")
require(tidyverse)

licordata |>
  group_by(date, site) |>
  nest(.key = "lightdf") |>
  mutate(m = purrr::map(
    lightdf,
    ~ (lm(log(UP + 1) ~ depth, data = .x))
  )) |>
  mutate(k = purrr::map_dbl(m, ~
  -coef(.x)[2])) |>
  ggplot(aes(date, k)) +
geom_point(aes(fill = site))

Iz = I0 * exp(-zk)






```

