Created
July 18, 2025 06:55
-
-
Save tukachev/cdef58a4fd8076a12f95aeb797747371 to your computer and use it in GitHub Desktop.
Воспроизводим графики с помощью ggplot2 из кн. Зейгарник Б.В. Введение в патопсихологию. М., 1969
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
| # Воспроизводим графики с помощью ggplot2 | |
| # из кн. Зейгарник Б.В. Введение в патопсихологию. М., 1969 | |
| library(ggplot2) | |
| library(patchwork) | |
| # Данные для Больной С. | |
| data_patient_S <- data.frame(time = 1:10, | |
| errors = c(2, 2, 3, 5, 5, 7, 6, 2, 2.5, 8)) | |
| # Данные для Больной Л. | |
| data_patient_L <- data.frame(time = 1:11, | |
| errors = c(3, 4, 1.5, 1.5, 3, 5, 7, 7, 5, 4, 3)) | |
| # Кастомная тема для графиков | |
| book_theme <- theme_minimal(base_family = "Helvetica") + | |
| theme( | |
| panel.grid = element_blank(), | |
| axis.line = element_line(color = "black"), | |
| axis.ticks = element_line(color = "black", linewidth = 0.25), | |
| axis.ticks.length = unit(-0.2, "cm"), | |
| axis.text = element_text(face = "italic", margin = margin(5, 5, 5, 5)), | |
| axis.title = element_text(face = "italic"), | |
| plot.title = element_text(hjust = 0.5, face = "italic"), | |
| plot.margin = margin(5, 5, 5, 5) | |
| ) | |
| # График Больной С. | |
| plot_patient_S <- ggplot(data_patient_S, aes(x = time, y = errors)) + | |
| geom_line(color = "black") + | |
| geom_point(shape = 21, | |
| fill = "white", | |
| size = 2) + | |
| scale_x_continuous(breaks = 1:10) + | |
| scale_y_continuous(limits = c(0, 10), breaks = 0:10) + | |
| labs(title = "Больная С.", x = NULL, y = "Количество ошибок в минуту") + | |
| book_theme | |
| # График Больной Л. | |
| plot_patient_L <- ggplot(data_patient_L, aes(x = time, y = errors)) + | |
| geom_line(color = "black") + | |
| geom_point(shape = 21, | |
| fill = "white", | |
| size = 2) + | |
| scale_x_continuous(breaks = 1:11) + | |
| scale_y_continuous(limits = c(0, 10), breaks = 0:10) + | |
| labs(title = "Больная Л.", x = NULL, y = NULL) + | |
| theme(axis.text.y = element_blank(), axis.ticks.y = element_blank()) + | |
| book_theme | |
| # Общая подпись к графикам для оси X | |
| bottom_label <- ggplot() + | |
| theme_void() + | |
| annotate( | |
| "text", | |
| x = 0.5, | |
| y = 0.5, | |
| label = "Время в минутах", | |
| fontface = "italic", | |
| family = "Helvetica", | |
| size = 4 | |
| ) | |
| # Объединяем графики и подпись к X | |
| final_plot <- (plot_patient_S + plot_patient_L) / bottom_label + | |
| plot_layout(heights = c(15, 1)) | |
| ggsave(filename = "ussr_dataviz.png", | |
| final_plot, width = 7, height = 5, dpi = 300, bg = "white") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment