library(readxl) library(tidyr) library(dplyr) library(ggplot2) library(tidyverse) library(svglite) library(lubridate) library(stringr) # ACETOSA_S2_GRONOSTAJOWA_SHORT data_gron_a_s2 <- read.table( file = "X:/My Drive/staz_UJ/Rumex manuscript data analysis/Gronostajowa/tabela_gronostajowa_acetosa_s2.tsv", sep = '\t', header = TRUE, na.strings = "NA", check.names = FALSE ) data_filtered <- data_gron_a_s2 %>% filter(sex != "0", name != "A099") %>% mutate( sex = as.character(sex), name = as.character(name) ) %>% arrange(sex, desc(name)) %>% mutate(across(starts_with("2020") | starts_with("2021"), as.character)) data_long <- data_filtered %>% select(name, sex, starts_with("2020"), starts_with("2021")) %>% pivot_longer( cols = starts_with("2020") | starts_with("2021"), names_to = "date", values_to = "value" ) %>% filter(str_sub(date, 1, 10) <= "2021.06.23") %>% arrange(sex, desc(name)) %>% mutate(y_axis = factor(paste(sex, name), levels = unique(paste(sex, name)))) data_long <- data_long %>% mutate( value = factor(value, levels = c( "w", # winter "l", # leaves "fm1", "fm2", # male flowering "ff1", "ff2", # female flowering "p1", "p2", # pollination "s1", "s2", # seed production "y" # senescing )) ) date_breaks <- c( "2020.10.20-2021.04.01 winter", "2021.04.02", "2021.04.08", "2021.04.16", "2021.04.23", "2021.04.29", "2021.05.03", "2021.05.07", "2021.05.10", "2021.05.12", "2021.05.17", "2021.05.21", "2021.05.24", "2021.05.28", "2021.06.02", "2021.06.07", "2021.06.11", "2021.06.14", "2021.06.16", "2021.06.18", "2021.06.21", "2021.06.23", "2021.06.23 inflorescence cut" ) tabela_gronostajowa_acetosa_s2 <- ggplot(data_long, aes(x = date, y = y_axis)) + geom_tile(aes(fill = value), color = "darkslategray", width = 1, height = 1) + scale_fill_manual( values = c( "w" = "orange2", "l" = "limegreen", "fm1" = "cyan", "fm2" = "cyan", "ff1" = "lightskyblue1", "ff2" = "lightskyblue1", "p1" = "yellow1", "p2" = "yellow1", "s1" = "plum2", "s2" = "plum2", "y" = "goldenrod4" ), name = "Legend", labels = c( "w" = "winter", "l" = "leaves", "fm1" = "male flowering", "fm2" = "male flowering", "ff1" = "female flowering", "ff2" = "female flowering", "p1" = "pollination", "p2" = "pollination", "s1" = "seed production", "s2" = "seed production", "y" = "senescing" ), na.value = "white" ) + scale_x_discrete( position = "top", breaks = date_breaks ) + theme_minimal() + theme( axis.text.x = element_text(angle = 90, hjust = 0, vjust = 0, size = 30, color = "black"), axis.text.x.top = element_text(angle = 90, hjust = 0, vjust = 0, size = 30, color = "black"), axis.text.x.bottom = element_blank(), axis.text.y = element_text(size = 30, color = "black"), panel.grid = element_blank(), axis.title = element_blank(), legend.position = "right", legend.title = element_text(size = 40, face = "bold", color = "black"), legend.text = element_text(size = 30, color = "black"), legend.background = element_rect(fill = "white", color = "white"), legend.box.background = element_rect(fill = "white", color = "black", size = 1), legend.box.margin = margin(10, 10, 10, 10) ) + labs(fill = "Wartość") ggsave("tabela_gronostajowa_acetosa_s2.png", plot = tabela_gronostajowa_acetosa_s2, width = 50, height = 20, limitsize = FALSE) ggsave("tabela_gronostajowa_acetosa_s2.svg", plot = tabela_gronostajowa_acetosa_s2, width = 50, height = 20, limitsize = FALSE) # THYRSIFLORUS_S2_GRONOSTAJOWA_SHORT data_gron_t_s2 <- read.table( file = "X:/My Drive/staz_UJ/Rumex manuscript data analysis/Gronostajowa/tabela_gronostajowa_thyrsiflorus_s2.tsv", sep = '\t', header = TRUE, na.strings = "NA", check.names = FALSE ) data_filtered <- data_gron_t_s2 %>% filter(sex != "0") %>% mutate( sex = as.character(sex), name = as.character(name) ) %>% arrange(sex, desc(name)) %>% mutate(across(starts_with("2020") | starts_with("2021"), as.character)) data_long <- data_filtered %>% select(name, sex, starts_with("2020"), starts_with("2021")) %>% pivot_longer( cols = starts_with("2020") | starts_with("2021"), names_to = "date", values_to = "value" ) %>% filter(str_sub(date, 1, 10) <= "2021.06.23") %>% arrange(sex, desc(name)) %>% mutate(y_axis = factor(paste(sex, name), levels = unique(paste(sex, name)))) data_long <- data_long %>% mutate( value = factor(value, levels = c( "w", # winter "l", # leaves "fm1", "fm2", # male flowering "ff1", "ff2", # female flowering "p1", "p2", # pollination "s1", "s2", # seed production "y" # senescing )) ) date_breaks <- c( "2020.10.20-2021.04.01 winter", "2021.04.02", "2021.04.08", "2021.04.16", "2021.04.23", "2021.04.29", "2021.05.03", "2021.05.07", "2021.05.10", "2021.05.12", "2021.05.17", "2021.05.21", "2021.05.24", "2021.05.28", "2021.06.02", "2021.06.07", "2021.06.11", "2021.06.14", "2021.06.16", "2021.06.18", "2021.06.21", "2021.06.23", "2021.06.23 inflorescence cut" ) tabela_gronostajowa_thyrsiflorus_s2 <- ggplot(data_long, aes(x = date, y = y_axis)) + geom_tile(aes(fill = value), color = "darkslategray", width = 1, height = 1) + scale_fill_manual( values = c( "w" = "orange2", "l" = "limegreen", "fm1" = "cyan", "fm2" = "cyan", "ff1" = "lightskyblue1", "ff2" = "lightskyblue1", "p1" = "yellow1", "p2" = "yellow1", "s1" = "orchid1", "s2" = "orchid1", "y" = "goldenrod4" ), name = "Legend", labels = c( "w" = "winter", "l" = "leaves", "fm1" = "male flowering", "fm2" = "male flowering", "ff1" = "female flowering", "ff2" = "female flowering", "p1" = "pollination", "p2" = "pollination", "s1" = "seed production", "s2" = "seed production", "y" = "senescing" ), na.value = "white" ) + scale_x_discrete( position = "top", breaks = date_breaks ) + theme_minimal() + theme( axis.text.x = element_text(angle = 90, hjust = 0, vjust = 0, size = 30, color = "black"), axis.text.x.top = element_text(angle = 90, hjust = 0, vjust = 0, size = 30, color = "black"), axis.text.x.bottom = element_blank(), axis.text.y = element_text(size = 30, color = "black"), panel.grid = element_blank(), axis.title = element_blank(), legend.position = "right", legend.title = element_text(size = 40, face = "bold", color = "black"), legend.text = element_text(size = 30, color = "black"), legend.background = element_rect(fill = "white", color = "white"), legend.box.background = element_rect(fill = "white", color = "black", size = 1), legend.box.margin = margin(10, 10, 10, 10) ) + labs(fill = "Wartość") ggsave("tabela_gronostajowa_thyrsiflorus_s2.png", plot = tabela_gronostajowa_thyrsiflorus_s2, width = 50, height = 20, limitsize = FALSE) ggsave("tabela_gronostajowa_thyrsiflorus_s2.svg", plot = tabela_gronostajowa_thyrsiflorus_s2, width = 50, height = 20, limitsize = FALSE)