Введение

Добрый день! В качесвте примера для домашней работы взял графики и таблицы из прошлых домашних работ. Исходные данные я брал из облака. Вот что из этого получилось:

Графики

Домашний график от 24.10.

На нем можно рассмотреть разницу в возрасте у подвидов моржей.

library(readxl)
library(tidyverse)
library(dplyr)
S <- read_excel("Гематологический скрининг моржей.xlsx")
S %>% 
  mutate(dw = weight.2019 - weight.2019) %>% 
  filter(!is.na(age)) %>% 
  group_by(Sex, subspecies) %>%
  summarise(age1 = mean(age), .groups = "drop_last") %>% 
  pivot_wider(names_from = Sex, values_from = age1) %>% 
  transmute(subspecies, dage = `F` - M) %>% 
  ggplot(aes(x = subspecies, y = dage)) +
  geom_col()+
  coord_flip()+
  labs(y = "Разница в возрасте", x = NULL,
       title = "Разница в возрасте у подвидов")

Домашний график от 31.10.

На нем можно рассмотреть линию тренда.

hw <- read_excel("homework_LM..xlsx",sheet = "Var._22")
fit <- lm(x ~ y, data = hw)
cbind(hw, fitted = fit$fitted.values) %>% 
  ggplot() + 
  geom_line( mapping = aes(x = x, y = fitted)) +
  geom_abline(aes(intercept = fit$coefficients[1],
                  slope = fit$coefficients[2])) + 
  geom_segment(mapping = aes(x = x, xend = x, 
                             y = fitted, yend = y),
               color = "blue", linetype = "dotted")+
  geom_point(mapping = aes(x = x, y = y), 
             shape = 21, fill = "white")  +
  labs(x = "x", y = "y",
       subtitle = "Домашний график") + 
  theme_dark() 

Таблица

В качестве таблицы решил выбрать первый файл с металлами. И сравнил таблицу в базовом виде и в formattable.

Базовый

Выриант этой таблицы выглядит не очень понятно.

m <- read_excel("metals.xlsx")
m
## # A tibble: 20 × 11
##      `№` Cu_soil Zn_soil Ni_soil Cu_plants Zn_pl…¹ Ni_pl…² slope dista…³ dista…⁴
##    <dbl>   <dbl>   <dbl>   <dbl>     <dbl>   <dbl>   <dbl> <chr> <chr>   <chr>  
##  1     1    31.1    45.1    27.6     33.2     20.2    5.12 сере… 200-400 200-400
##  2     2    28.4    43.9    24.8     24.2     49      2.95 низ   200-400 200-400
##  3     3    55.1    60.8    17.4     60.5     18.3   60.8  верх  200-400 200-400
##  4     4    41.4    52.0    39.2     27.0     43.1   35.0  низ   400-600 400-600
##  5     5    35      53.4    44.0     21.9     30.6   46.1  низ   400-600 400-600
##  6     6    11.9    35.1    15.0     35.7     15.3   34.6  верх  600-800 200-400
##  7     7    60.1    90.8    39.3     21.7     37.0   32.4  низ   600-800 400-600
##  8     8    45.2    71.6    50.2     21.3     52.0   56.7  низ   600-800 400-600
##  9     9    19.7    57.5    29.4     56.3     30.2   57.3  верх  600-800 400-600
## 10    10    15.6    45.1    19.4     45.9     20.1   46.2  верх  600-800 400-600
## 11    11    39.1    54.0    33.0     11.5     25.0   14.5  низ   400-600 600-800
## 12    12    67.0    60.5    45.3     25.9     36.6   37.9  низ   400-600 600-800
## 13    13    22.2    40.5    37.2      1.8     19.6   20.2  сере… 600-800 600-800
## 14    14    53.9    98.0    77.2     14.8     38.2   33.1  низ   200-400 400-600
## 15    15    62.4    73.1    61.4     18.4     38.8   20.6  низ   0-200   600-800
## 16    16    57      79.1    56.0     20.0     41.8   10.8  низ   200-400 600-800
## 17    17    69.7    75.5    80.6     35.7     31.8   49.3  низ   0-200   800+   
## 18    18    54.4    83.1    75.9     19.2     35     38.5  низ   0-200   800+   
## 19    19    26.3    50.3    43        2.55    18.0    7.55 сере… 400-600 800+   
## 20    20    42.9    48.3    60.1     32.6     16.8   26.6  сере… 0-200   400-600
## # … with 1 more variable: exposition <chr>, and abbreviated variable names
## #   ¹​Zn_plants, ²​Ni_plants, ³​distance_to_road, ⁴​distance_to_oil.cluster

Formattable

В формате formattable таблица выгляди визуально лучше и легче воспринимается информация.

formattable::formattable(m)
№ Cu_soil Zn_soil Ni_soil Cu_plants Zn_plants Ni_plants slope distance_to_road distance_to_oil.cluster exposition
1 31.10 45.14 27.64 33.17 20.15 5.12 середина 200-400 200-400 В
2 28.45 43.93 24.80 24.20 49.00 2.95 низ 200-400 200-400 В
3 55.12 60.77 17.37 60.53 18.26 60.81 верх 200-400 200-400 ЮВ
4 41.35 52.04 39.15 27.05 43.06 35.04 низ 400-600 400-600 ЮВ
5 35.00 53.41 44.02 21.92 30.59 46.11 низ 400-600 400-600 ЮВ
6 11.86 35.14 15.01 35.67 15.27 34.62 верх 600-800 200-400 В
7 60.09 90.84 39.30 21.68 37.01 32.40 низ 600-800 400-600 Ю
8 45.17 71.65 50.15 21.30 52.02 56.70 низ 600-800 400-600 Ю
9 19.72 57.48 29.44 56.26 30.20 57.26 верх 600-800 400-600 В
10 15.65 45.13 19.37 45.87 20.07 46.21 верх 600-800 400-600 В
11 39.14 53.99 32.96 11.51 25.04 14.53 низ 400-600 600-800 ЮВ
12 67.01 60.49 45.28 25.90 36.63 37.90 низ 400-600 600-800 Ю
13 22.16 40.50 37.15 1.80 19.65 20.19 середина 600-800 600-800 В
14 53.90 98.05 77.24 14.85 38.21 33.08 низ 200-400 400-600 Ю
15 62.43 73.06 61.39 18.39 38.80 20.60 низ 0-200 600-800 Ю
16 57.00 79.13 56.01 20.03 41.80 10.82 низ 200-400 600-800 Ю
17 69.70 75.47 80.55 35.67 31.82 49.33 низ 0-200 800+ В
18 54.35 83.10 75.93 19.18 35.00 38.51 низ 0-200 800+ Ю
19 26.30 50.31 43.00 2.55 18.05 7.55 середина 400-600 800+ ЮВ
20 42.91 48.33 60.14 32.65 16.80 26.61 середина 0-200 400-600 ЮВ

Конец

Это был полезный опыт попрактиковаться в Markdown и с помощью него отчетность выглядит более презентабельно.