Created
May 5, 2025 18:40
-
-
Save tukachev/baa31c06ebbf7b6b0f8af585508e93e5 to your computer and use it in GitHub Desktop.
Визуализация данных по тексту статьи от AI Grok-3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Установка и загрузка необходимых пакетов | |
if (!require(waffle)) install.packages("waffle") | |
if (!require(ggplot2)) install.packages("ggplot2") | |
if (!require(ggtext)) install.packages("ggtext") | |
if (!require(showtext)) install.packages("showtext") | |
library(waffle) | |
library(ggplot2) | |
library(ggtext) | |
library(showtext) | |
# Подключение Google Fonts через showtext | |
font_add_google("Roboto", "Roboto") | |
showtext_auto() | |
showtext_opts(dpi = 150) | |
# Данные: распределение пострадавших, с выделением курьеров внутри электровелосипедистов | |
data <- c(`Курьеры на электровелосипедах` = 47, `Другие электровелосипедисты` = 35, `Пешеходы` = 17, `Пассажиры` = 1) # 47 + 35 + 17 + 1 = 100 | |
# Создание waffle chart | |
p <- waffle(flip = TRUE, | |
data, | |
rows = 10, # 10 строк x 10 столбцов = квадратная сетка 100 квадратов | |
size = 0.5, # Отступы между квадратами | |
colors = c("#2C4A6B", "#7393B3", "#B0B7BC", "#5E6A77"), | |
title = "В 2024 году 47% ДТП с электровелосипедами\nсвязаны с курьерами доставки", | |
xlab = "1 квадрат = 1% от 1257 пострадавших" | |
) + | |
theme(plot.margin = margin(20, 20, 20, 20), | |
plot.title.position = "plot", plot.caption.position = "plot", | |
plot.title = element_text(family = "Roboto", size = 20, face = "bold", hjust = 0, margin = margin(b = 10)), | |
plot.subtitle = element_text(family = "Roboto", color = "gray30", size = 16, hjust = 0, margin = margin(b = 15)), | |
axis.title.x = element_text(family = "Roboto", size = 14), | |
legend.position = "top", | |
legend.text = element_text(family = "Roboto", size = 14), | |
legend.title = element_blank(), | |
legend.box="vertical", | |
plot.caption = element_text(family = "Roboto", color = "gray50", size = 12, hjust = 0, margin = margin(t = 20)) | |
) + | |
labs( | |
subtitle = "82% пострадавших — электровелосипедисты,\nвключая курьеров.\nБолее 600 человек сервисов доставки пострадали\nи 12 погибли в результате ДТП.", | |
caption = "Источник: ТАСС, 6 апреля 2025 URL: https://tass.ru/obschestvo/23609791\nВизуализация: AI Grok на основе диалога с пользователем" | |
) + | |
scale_fill_manual( | |
values = c("#2C4A6B", "#7393B3", "#B0B7BC", "#5E6A77"), | |
labels = c("Курьеры (47.2%)", "Электровелосипедисты (34.8%)", "Пешеходы (17.4%)", "Пассажиры (0.6%)") | |
) + | |
guides(fill=guide_legend(nrow=2)) | |
# Сохранение изображения | |
ggsave("ebike_injured_waffle.png", bg = "white", plot = p, width = 7, height = 10, dpi = 150) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment