library(dplyr)
library(tidyverse)
library(base)
library(lubridate)
library(ggplot2)
library(webr)
library(plotly)
data <- read.table(file = "C:\\Users\\Simona\\Desktop\\Personal_Portfolio\\Biobank_LT\\biobank.txt", header = TRUE, sep = ',')
data
glimpse(data)
## Rows: 17,750
## Columns: 15
## $ emimprefix <chr> "TE", "TE", "TE", "TE", "TE", "TE", "TE", "TE", "TE", "TE…
## $ megnrsuffix <chr> "N05", "N04", "N03", "N02", "N01", "A05", "A04", "A03", "…
## $ megmetai <int> 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 201…
## $ megmen <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 12, 12, 12, 12, 12, 12, 12,…
## $ amzgr <chr> "20-24", "20-24", "20-24", "20-24", "20-24", "20-24", "20…
## $ lytis <chr> "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V…
## $ dgn <chr> "", "", "", "", "", "", "", "", "", "", "C64", "C64", "C6…
## $ pt <chr> "", "", "", "", "", "", "", "", "", "", "1b", "1b", "1b",…
## $ pn <chr> "", "", "", "", "", "", "", "", "", "", "0", "0", "0", "0…
## $ pm <chr> "", "", "", "", "", "", "", "", "", "", "0", "0", "0", "0…
## $ lokalizacija <chr> "Sėklidės", "Sėklidės", "Sėklidės", "Sėklidės", "Sėklidės…
## $ megpavad <chr> "Navikas", "Navikas", "Navikas", "Navikas", "Navikas", "S…
## $ indpavad <chr> "Kriomėgintuvėlis", "Kriomėgintuvėlis", "Kriomėgintuvėlis…
## $ kiekis <dbl> 0.10, 0.10, 0.10, 0.32, 0.28, 0.11, 0.11, 0.11, 0.10, 0.1…
## $ vnt <chr> "gr.", "gr.", "gr.", "gr.", "gr.", "gr.", "gr.", "gr.", "…
data$ID <- paste(data$emimprefix, data$megnrsuffix, sep = "")
data
unique(data$ID)
## [1] "TEN05" "TEN04" "TEN03" "TEN02" "TEN01" "TEA05" "TEA04"
## [8] "TEA03" "TEA02" "TEA01" "RENSL04" "RENSL03" "RENSL02" "RENSL01"
## [15] "RENS02" "RENS01" "RENP04" "RENP03" "RENP02" "RENP01" "RENL02"
## [22] "RENL01" "RENK04" "RENK03" "RENK02" "RENK01" "RENN05" "RENN04"
## [29] "RENN03" "RENN02" "RENN01" "RENA05" "RENA04" "RENA03" "RENA02"
## [36] "RENA01" "RENP05" "RENSL05" "RENK07" "RENK06" "RENK05" "RECSL04"
## [43] "RECSL03" "RECSL02" "RECSL01" "RECS02" "RECS01" "RECP02" "RECP01"
## [50] "RECL02" "RECL01" "RECK04" "RECK03" "RECK02" "RECK01" "RECP04"
## [57] "RECP03" "RECN05" "RECN04" "RECN03" "RECN02" "RECN01" "RECA05"
## [64] "RECA04" "RECA03" "RECA02" "RECA01" "PROSL04" "PROSL03" "PROSL02"
## [71] "PROSL01" "PROS02" "PROS01" "PROP04" "PROP03" "PROP02" "PROP01"
## [78] "PRON02" "PRON01" "PROL02" "PROL01" "PROK04" "PROK03" "PROK02"
## [85] "PROK01" "PRON03" "PROP05" "PROSL05" "PROL03" "PROS03" "PLSL04"
## [92] "PLSL03" "PLSL02" "PLSL01" "PLS02" "PLS01" "PLP04" "PLP03"
## [99] "PLP02" "PLP01"
## [ reached getOption("max.print") -- omitted 84 entries ]
df <- data %>% distinct()
df
df_renamed <-
df %>%
rename(age_group = amzgr,
sex = lytis,
diagnosis = dgn,
localization = lokalizacija,
stored_sample = megpavad,
container = indpavad,
amount = kiekis,
measurmement = vnt,
year = megmetai
)
df_renamed
df_renamed_rv <-
df_renamed %>%
mutate(localization = recode(localization,
"Gimdos kūnas" = "Uterus",
"Inkstai" = "Kidneys",
"Kiaušidės" = "Ovaries",
"Krūtis" = "Breast",
"Melanoma" = "Melanoma",
"Plaučiai" = "Lungs",
"Prostatos biopsija" = "Prostate",
"Sėklidės" ="Testicles",
"Žarnynas" ="Intestine"))
df_renamed_rv
df_full <- subset(df_renamed_rv, select = -c(megmen, emimprefix, megnrsuffix))
df_full
df_full$diagnosis <- sub(".\\d+","Cancerous", df_full$diagnosis)
df_full
df_full$diagnosis <- sub("^$","Non-cancerous", df_full$diagnosis)
df_full
breaks_y = c(0, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000)
plot1 <- ggplot(df_full, aes(x = age_group, fill = localization)) +
geom_bar() +
labs(x = "Age group", y = "Counts per Localization", title = "Stored Samples by Age Group at NVI Biobank", color = "Localization", fill = "Localization") +
scale_y_continuous(limits = c(0, 4000), breaks = breaks_y) +
theme_bw() +
theme(axis.text = element_text(size = 9),
axis.title.y = element_text(size = 12, face ="bold"),
axis.title.x = element_text(size = 12, face ="bold"),
legend.title=element_text(size=10, face ="bold"),
legend.text=element_text(size=10),
axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(size = 12, face = "bold"))
ggplotly(plot1)
breaks_y = c(0, 1000, 2000, 3000, 4000)
df_full_mod <- df_full %>%
mutate(sex = recode(sex, "V" = "Male", "M" = "Female"))
plot2 <- ggplot(df_full_mod, aes(x = year, fill = localization)) +
geom_bar() +
facet_wrap(vars(sex)) +
labs(x = "Year of Collection", y = "Counts per Localization", title = "Stored Samples by Sex at NVI Biobank", color = "Localization", fill = "Localization") +
scale_y_continuous(limits = c(0, 4000, breaks = breaks_y)) +
scale_fill_discrete(labels=c("Gimdos kūnas" = "Uterus",
"Inkstai" = "Kidneys",
"Kiaušidės" = "Ovaries",
"Krūtis" = "Breast",
"Melanoma" = "Melanoma",
"Plaučiai" = "Lungs",
"Prostatos biopsija" = "Prostate biopsy",
"Sėklidės" ="Testicles",
"Žarnynas" ="Intestine")) +
theme_bw() +
theme(axis.text = element_text(size = 9),
axis.title.y = element_text(size = 12, face ="bold"),
axis.title.x = element_text(size = 12, face ="bold"),
legend.title=element_text(size=10, face ="bold"),
legend.text=element_text(size=10),
plot.title = element_text(size = 12, face = "bold"))
ggplotly(plot2_flip)
breaks_y = c(0, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000)
plot3 <- ggplot(df_full, aes(x = age_group, fill = localization)) +
geom_bar() +
facet_wrap(vars(diagnosis)) +
labs(x = "Age group", y = "Counts per Localization", title = "Stored Samples by Diagnosis and Age Group at NVI Biobank", color = "Localization", fill = "Localization") +
scale_y_continuous(limits = c(0, 4000), breaks = breaks_y) +
scale_fill_discrete(labels=c("Gimdos kūnas" = "Uterus",
"Inkstai" = "Kidneys",
"Kiaušidės" = "Ovaries",
"Krūtis" = "Breast",
"Melanoma" = "Melanoma",
"Plaučiai" = "Lungs",
"Prostatos biopsija" = "Prostate biopsy",
"Sėklidės" ="Testicles",
"Žarnynas" ="Intestine")) +
theme_bw() +
theme(axis.text = element_text(size = 9),
axis.title.y = element_text(size = 12, face ="bold"),
axis.title.x = element_text(size = 12, face ="bold"),
legend.title=element_text(size=10, face ="bold"),
legend.text=element_text(size=10),
axis.text.x = element_text(angle = 90, hjust = 1),
plot.title = element_text(size = 12, face = "bold"))
ggplotly(plot3)