Создание документов в формате HTML, PDF, и MS Word documents. Подробнее на сайте R Markdown http://rmarkdown.rstudio.com.
Работа над шрифтом: полужирный,
курсив, полужирный курсив,
перечёркнутый текст
Можно добавить ссылку на источник, ресурс или что-то другое. Например, на статью “ДЕМОГРАФИЧЕСКИЕ ОСОБЕННОСТИ ПОПУЛЯЦИЙ ОЗЕРНОЙ ЛЯГУШКИ (RANA RIDIBUNDA PALL.), ИНТРОДУЦИРОВАННОЙ В ВОДОЕМЫ СРЕДНЕГО УРАЛА”.
Просмотр получившегося документа через кнопку Knit.
Можно встроить блоки кода (чанк), не забывая сохранять их содержимое (на примере четвертой домашней работы):
s <- readxl::read_excel("Caspian spiders.xlsx") %>%
pivot_longer(-1:-4, names_to = "species", values_to = "individuals") %>%
filter(individuals > 0) %>%
group_by(id, coast, RH) %>%
summarise(
nsp = n(),
abu = sum(individuals),
.groups = "drop"
)
Нажав на шестеренку в чанке можно настроить что будет отображаться.
Можно создать вкладки страниц (в конце заголовка добавили{.tabset}, теперь подзаголовки будут вкладками), размещать изображения (заранее сохранить) и встроить графики. Для построения графика можно использовать пакет ploty (на основе графика ggplot), в котором графики будут интерактивными.
ggplot(s, aes(x = abu, y = nsp, color = coast)) +
geom_point(size = 3) +
geom_smooth(formula = "y ~ x", method = "lm") +
geom_abline(slope = 0.03, intercept = 6, color = "green") +
geom_abline(slope = 0.3, intercept = -6, color = "green") +
labs(
title = "Caspian spiders",
subtitle = "Number of species ~ abundance",
x = "Abundance",
y = "Number of species"
)+
theme_bw() +
theme(legend.position = "bottom")
grafik2 <- s %>%
filter(coast != "reeds") %>%
ggplot(aes(x = coast, y = nsp, color = coast, fill = coast)) +
geom_boxplot(color = "black") +
scale_fill_manual(values = c("beige", "gray", "yellow")) +
scale_x_discrete(labels = c("Дюны", "Галечник", "Песчаный пляж")) +
labs(x = NULL) +
theme_classic() +
theme(legend.position = "bottom")
ggplotly(grafik2)
Для создания таких карт используется пакет leaflet. Между строчками кода не ставится “+”! Если собранные данные с координатами, то они отобразятся на фоне карты. Также можно ввести координаты вручную.
leaflet() %>%
addTiles() %>%
addMarkers(
lng = c(37.6173, 60.6057, 60.6533, 60.6193),
lat = c(55.7558, 56.8389, 56.8446, 56.8282),
popup = c("Москва", "Екатеринбург", "ГУК УрФУ", "ИЕНиМ УрФУ")
)
formattable(s)
| id | coast | RH | nsp | abu |
|---|---|---|---|---|
| PbAe1 | pebbly | 31.9717600 | 1 | 1 |
| PbAe3 | pebbly | 31.9802909 | 2 | 2 |
| PbAe5 | pebbly | 32.8219433 | 1 | 1 |
| PbDe1 | pebbly | 29.7359357 | 2 | 2 |
| PbDe2 | pebbly | 31.9729330 | 2 | 2 |
| PbDe3 | pebbly | 30.5540613 | 1 | 4 |
| PbDe4 | pebbly | 28.2292156 | 5 | 29 |
| PbDe5 | pebbly | 33.9622642 | 3 | 35 |
| PbPo1 | pebbly | 27.5301205 | 3 | 4 |
| PbPo2 | pebbly | 32.8936743 | 1 | 2 |
| PbPo3 | pebbly | 33.7974684 | 10 | 49 |
| PbPo4 | pebbly | 34.0253165 | 5 | 53 |
| PbPo5 | pebbly | 24.2591316 | 3 | 10 |
| PbTl1 | pebbly | 31.9814600 | 1 | 1 |
| PbTl2 | pebbly | 28.5714286 | 11 | 43 |
| PbTl3 | pebbly | 30.0776915 | 9 | 24 |
| PbTl4 | pebbly | 33.5314685 | 5 | 16 |
| PbTl5 | pebbly | 26.9458712 | 12 | 53 |
| PbTu1 | pebbly | 32.8875090 | 8 | 26 |
| PbTu2 | pebbly | 32.4273664 | 13 | 75 |
| PbTu3 | pebbly | 31.5101899 | 13 | 146 |
| PbTu4 | pebbly | 30.8875360 | 6 | 8 |
| PbTu5 | pebbly | 32.4981017 | 14 | 38 |
| RsFd1 | reeds | 24.5621181 | 19 | 98 |
| RsFd2 | reeds | 26.6263238 | 14 | 52 |
| RsFd3 | reeds | 26.2936475 | 16 | 62 |
| RsFd4 | reeds | 28.8649204 | 16 | 106 |
| RsFd5 | reeds | 31.9535588 | 16 | 203 |
| SdCJ1 | dunes | 3.3097686 | 2 | 3 |
| SdCJ2 | dunes | 5.5804340 | 2 | 3 |
| SdCJ3 | dunes | 9.8338870 | 2 | 6 |
| SdCJ4 | dunes | 6.5529923 | 1 | 2 |
| SdCJ5 | dunes | 6.5536355 | 1 | 1 |
| SdCS1 | dunes | 2.2787029 | 6 | 25 |
| SdCS2 | dunes | 1.3902681 | 5 | 27 |
| SdCS3 | dunes | 2.6631158 | 5 | 37 |
| SdCS4 | dunes | 1.1450382 | 5 | 33 |
| SdCS5 | dunes | 0.5416667 | 5 | 28 |
| SdEc1 | sandy beach | 19.3536122 | 6 | 15 |
| SdEc2 | sandy beach | 28.0592362 | 9 | 181 |
| SdEc3 | sandy beach | 28.5611511 | 14 | 278 |
| SdEc4 | sandy beach | 14.2454161 | 9 | 38 |
| SdEc5 | sandy beach | 29.3262239 | 15 | 112 |
| SdEq1 | sandy beach | 25.9322034 | 9 | 55 |
| SdEq2 | sandy beach | 23.0835985 | 7 | 48 |
| SdEq3 | sandy beach | 23.0694354 | 7 | 14 |
| SdEq4 | sandy beach | 26.0514019 | 8 | 34 |
| SdEq5 | sandy beach | 25.3725332 | 5 | 80 |
| SdFn1 | sandy beach | 47.7828429 | 12 | 146 |
| SdFn2 | sandy beach | 45.3157895 | 16 | 156 |
| SdFn3 | sandy beach | 28.0857952 | 10 | 65 |
| SdFn4 | sandy beach | 22.1399482 | 7 | 16 |
| SdFn5 | sandy beach | 29.9861496 | 11 | 19 |
| SdJj1 | sandy beach | 27.0052734 | 10 | 144 |
| SdJj2 | sandy beach | 26.4773379 | 7 | 82 |
| SdJj3 | sandy beach | 28.0619298 | 4 | 8 |
| SdJj4 | sandy beach | 27.1174119 | 6 | 64 |
| SdJj5 | sandy beach | 30.6015038 | 7 | 44 |
| SdJm1 | sandy beach | 25.3587024 | 9 | 97 |
| SdJm2 | sandy beach | 24.8106744 | 7 | 30 |
| SdJm3 | sandy beach | 20.2730375 | 10 | 68 |
| SdJm4 | sandy beach | 24.7879722 | 3 | 85 |
| SdJm5 | sandy beach | 24.2492492 | 5 | 21 |
| SdTa1 | sandy beach | 28.5714286 | 8 | 57 |
| SdTa2 | sandy beach | 25.9383129 | 11 | 79 |
| SdTa3 | sandy beach | 29.5734101 | 12 | 267 |
| SdTa4 | sandy beach | 30.5990080 | 6 | 11 |
| SdTa5 | sandy beach | 25.5667038 | 6 | 20 |
| SdTu1 | sandy beach | 23.6719082 | 8 | 130 |
| SdTu2 | sandy beach | 22.4859875 | 8 | 41 |
| SdTu3 | sandy beach | 23.0740464 | 9 | 50 |
| SdTu4 | sandy beach | 24.1089307 | 6 | 12 |
| SdTu5 | sandy beach | 22.6672172 | 7 | 15 |
formattable(s, list(
nsp = color_tile("white", "lightgreen"),
abu = color_tile("white", "red"),
coast = formatter("span",
style = x ~ style(
display = "block",
padding = "4px 8px",
`border-radius` = "12px",
`font-weight` = "bold",
`background-color` = case_when(
x == "pebbly" ~ "gray",
x == "reeds" ~ "green",
x == "dunes" ~ "beige",
x == "sandy beach" ~ "yellow",
TRUE ~ "white")))))
| id | coast | RH | nsp | abu |
|---|---|---|---|---|
| PbAe1 | pebbly | 31.9717600 | 1 | 1 |
| PbAe3 | pebbly | 31.9802909 | 2 | 2 |
| PbAe5 | pebbly | 32.8219433 | 1 | 1 |
| PbDe1 | pebbly | 29.7359357 | 2 | 2 |
| PbDe2 | pebbly | 31.9729330 | 2 | 2 |
| PbDe3 | pebbly | 30.5540613 | 1 | 4 |
| PbDe4 | pebbly | 28.2292156 | 5 | 29 |
| PbDe5 | pebbly | 33.9622642 | 3 | 35 |
| PbPo1 | pebbly | 27.5301205 | 3 | 4 |
| PbPo2 | pebbly | 32.8936743 | 1 | 2 |
| PbPo3 | pebbly | 33.7974684 | 10 | 49 |
| PbPo4 | pebbly | 34.0253165 | 5 | 53 |
| PbPo5 | pebbly | 24.2591316 | 3 | 10 |
| PbTl1 | pebbly | 31.9814600 | 1 | 1 |
| PbTl2 | pebbly | 28.5714286 | 11 | 43 |
| PbTl3 | pebbly | 30.0776915 | 9 | 24 |
| PbTl4 | pebbly | 33.5314685 | 5 | 16 |
| PbTl5 | pebbly | 26.9458712 | 12 | 53 |
| PbTu1 | pebbly | 32.8875090 | 8 | 26 |
| PbTu2 | pebbly | 32.4273664 | 13 | 75 |
| PbTu3 | pebbly | 31.5101899 | 13 | 146 |
| PbTu4 | pebbly | 30.8875360 | 6 | 8 |
| PbTu5 | pebbly | 32.4981017 | 14 | 38 |
| RsFd1 | reeds | 24.5621181 | 19 | 98 |
| RsFd2 | reeds | 26.6263238 | 14 | 52 |
| RsFd3 | reeds | 26.2936475 | 16 | 62 |
| RsFd4 | reeds | 28.8649204 | 16 | 106 |
| RsFd5 | reeds | 31.9535588 | 16 | 203 |
| SdCJ1 | dunes | 3.3097686 | 2 | 3 |
| SdCJ2 | dunes | 5.5804340 | 2 | 3 |
| SdCJ3 | dunes | 9.8338870 | 2 | 6 |
| SdCJ4 | dunes | 6.5529923 | 1 | 2 |
| SdCJ5 | dunes | 6.5536355 | 1 | 1 |
| SdCS1 | dunes | 2.2787029 | 6 | 25 |
| SdCS2 | dunes | 1.3902681 | 5 | 27 |
| SdCS3 | dunes | 2.6631158 | 5 | 37 |
| SdCS4 | dunes | 1.1450382 | 5 | 33 |
| SdCS5 | dunes | 0.5416667 | 5 | 28 |
| SdEc1 | sandy beach | 19.3536122 | 6 | 15 |
| SdEc2 | sandy beach | 28.0592362 | 9 | 181 |
| SdEc3 | sandy beach | 28.5611511 | 14 | 278 |
| SdEc4 | sandy beach | 14.2454161 | 9 | 38 |
| SdEc5 | sandy beach | 29.3262239 | 15 | 112 |
| SdEq1 | sandy beach | 25.9322034 | 9 | 55 |
| SdEq2 | sandy beach | 23.0835985 | 7 | 48 |
| SdEq3 | sandy beach | 23.0694354 | 7 | 14 |
| SdEq4 | sandy beach | 26.0514019 | 8 | 34 |
| SdEq5 | sandy beach | 25.3725332 | 5 | 80 |
| SdFn1 | sandy beach | 47.7828429 | 12 | 146 |
| SdFn2 | sandy beach | 45.3157895 | 16 | 156 |
| SdFn3 | sandy beach | 28.0857952 | 10 | 65 |
| SdFn4 | sandy beach | 22.1399482 | 7 | 16 |
| SdFn5 | sandy beach | 29.9861496 | 11 | 19 |
| SdJj1 | sandy beach | 27.0052734 | 10 | 144 |
| SdJj2 | sandy beach | 26.4773379 | 7 | 82 |
| SdJj3 | sandy beach | 28.0619298 | 4 | 8 |
| SdJj4 | sandy beach | 27.1174119 | 6 | 64 |
| SdJj5 | sandy beach | 30.6015038 | 7 | 44 |
| SdJm1 | sandy beach | 25.3587024 | 9 | 97 |
| SdJm2 | sandy beach | 24.8106744 | 7 | 30 |
| SdJm3 | sandy beach | 20.2730375 | 10 | 68 |
| SdJm4 | sandy beach | 24.7879722 | 3 | 85 |
| SdJm5 | sandy beach | 24.2492492 | 5 | 21 |
| SdTa1 | sandy beach | 28.5714286 | 8 | 57 |
| SdTa2 | sandy beach | 25.9383129 | 11 | 79 |
| SdTa3 | sandy beach | 29.5734101 | 12 | 267 |
| SdTa4 | sandy beach | 30.5990080 | 6 | 11 |
| SdTa5 | sandy beach | 25.5667038 | 6 | 20 |
| SdTu1 | sandy beach | 23.6719082 | 8 | 130 |
| SdTu2 | sandy beach | 22.4859875 | 8 | 41 |
| SdTu3 | sandy beach | 23.0740464 | 9 | 50 |
| SdTu4 | sandy beach | 24.1089307 | 6 | 12 |
| SdTu5 | sandy beach | 22.6672172 | 7 | 15 |