Change working directory to location where files were placed that were generated after running notebook 4.
getwd()
setwd('//infoscidiv/users/jkaddis/Desktop/GitHub/ICU_study_nPOD_v3/SASUniversityEdition/myfolders')
getwd()
Diabetologia requires the use of Arial or Helvetica font, therefore need to install extra fonts. Only loading the arial based fonts, if all fonts were loaded, it would take several minutes.
library(extrafont)
font_import(pattern = 'arial')
loadfonts(device = "win")
other packages needed
library(tidyverse)
library(magrittr)
library(ggthemes)
library(plyr)
library(dplyr)
library(readr)
library(cowplot)
my_data <- read_csv("figure1.csv", col_names = TRUE)
my_data <- read_csv("figure1.csv", col_names = TRUE)
my_data %<>% mutate(days = paste("<", hospbin, "days", sep = " "))
my_data[my_data == "< 6 days"] <- "\u2265 3, <6 days"
my_data[my_data == "< 9 days"] <- "\u2265 6 days"
my_data[my_data == "dual"] <- "Ki67 + I"
my_data[my_data == "Insulin"] <- "Insulin(I)"
# for reordering the columns
my_data <- within(my_data,
pancreas_region <- factor(pancreas_region,
levels=rev(c("Head",
"Body",
"Tail",
"Overall"))))
colnames(my_data)
p <- ggplot(my_data, aes(pancreas_region, LSMEAN, color=pancreas_region, fill=pancreas_region)) + scale_color_manual(values =c("black", "black", "black", "black")) + scale_fill_manual(values=c("Head" = "white", "Body" = "grey90", "Tail" = "grey60", "Overall" = "black"))
#use below version for color
#p <- ggplot(my_data, aes(pancreas_region, LSMEAN, fill=factor(pancreas_region)))+ guides(fill=FALSE)
p_col <- p + geom_col(width = 0.5) +
coord_flip() +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"),
axis.text = element_text(colour = "black", size = 18, family="Arial"),
axis.title = element_text(size = 24, vjust=0, face="bold", family="Arial"),
panel.border = element_rect(color = "black")) +
theme(legend.position="none", panel.border = element_rect(color = "black")) +
xlab("Pancreas region") +
ylab("Positive cells (%)")
Fig1<-p_col + facet_grid(days ~ stain) + theme(strip.text.x = element_text(size = 17.5, family="Arial"), strip.text.y = element_text(size = 17.5, family="Arial"), panel.border = element_rect(color = "black"))
Fig1
ggsave("Fig1.tiff", dpi = 600, height=5.5)
Required to use Diabetologia color palette, so selected approved rgb colors at http://bit.ly/2cR5JJa and converted to HEX for use in R
rgb(138,169,214, maxColorValue=255) #blue
rgb(192,65,64, maxColorValue=255) #red
rgb(109,165,103, maxColorValue=255) #green
insulin <- read_csv("insulin.csv", col_names = TRUE)
insulin %<>% mutate(pancreas_region = ifelse(sample_type2 == "A", "Head",
ifelse(sample_type2 == "B", "Body",
"Tail")),
age_range = ifelse(age_group == 1, "< 12 years old",
ifelse(age_group == 2, "\u226512 to 20 years old",
"\u226520 years old")))
insulin$Case <- as.character(insulin$Case)
colnames(insulin)
#change order so that head is displayed first
insulin$pancreas_region <- factor(insulin$pancreas_region, levels = insulin$pancreas_region[order(insulin$sample_type2)])
p <- ggplot(insulin, aes(age_range, percent_insulin))
p <- ggplot(insulin, aes(oppc_ageR, percent_insulin))
ESM_fig2<-p + geom_jitter(aes(color = pancreas_region), alpha = 0.50, size=3) +
geom_smooth(aes(group = pancreas_region, color = pancreas_region), se = FALSE) +
scale_color_manual(values =c("#C04140", "#6DA567", "#8AA9D6")) + #comment this line out if you want to use R's auto-color palette
scale_fill_manual(values=c("Head" = "#C04140", "Body" = "#6DA567", "Tail" = "#8AA9D6")) + #comment this line out if you want to use R's auto-color palette
theme_few() +
ylab("Insulin+ cells (%)") +
xlab("Age (years)") +
labs(color = "Pancreas region") +
# replace none with the following to add the legend back into the figure: c(.785,.90)
theme(legend.position = "none",legend.text=element_text(size=18, face="bold", family="Arial"), legend.title=element_text(size=20, face="bold", family="Arial"),
axis.text=element_text(size=22, color="black", family="Arial"), axis.title=element_text(size=24, face="bold", family="Arial"), axis.ticks=element_line(color="black"),
panel.border = element_rect(color = "black")) +
geom_vline(xintercept = c(12, 20), linetype = "longdash", color = "black", size=0.5) +
annotate(geom = "text", x = 5, y = 20, label = "Children", color = "black", size=6.5, family="Arial") +
annotate(geom = "text", x = 16, y = 20, label = "Youth", color = "black", size=6.5, family="Arial") +
annotate(geom = "text", x = 35, y = 20, label = "Adults", color = "black", size=6.5, family="Arial")
ESM_fig2
#ggsave("ESM_fig2.png", dpi=600)
save_plot("ESM_fig2.tiff", ESM_fig2, dpi=600, base_aspect_ratio=1.5)
ki67 <- read_csv("ki67.csv", col_names = TRUE)
ki67 %<>% mutate(pancreas_region = ifelse(sample_type2 == "A", "Head",
ifelse(sample_type2 == "B", "Body",
"Tail")),
age_range = ifelse(age_group == 1, "< 12 ",
ifelse(age_group == 2, "\u226512, <20",
"\u226520")))
ki67$Case <- as.character(ki67$Case)
#change order so that region is displayed in proper order
ki67$pancreas_region <- factor(ki67$pancreas_region, levels = ki67$pancreas_region[order(ki67$sample_type2)])
#change order so that age is displayed in proper order
ki67$age_range <- factor(ki67$age_range, levels = ki67$age_range[order(ki67$age_group)])
colnames(ki67)
#need to calculate means at each level of each group, to plot simple effects
meanki67 <- ddply(ki67,.(age_range,pancreas_region),summarise, val = mean(percent_ki67))
meanki67
p <- ggplot(ki67, aes(age_range, percent_ki67))
ESM_Fig3<-p + geom_jitter(aes(color = pancreas_region), alpha=0.50, size=3, width = 0.25) +
geom_line(data=meanki67, aes(y=val, group=pancreas_region, color = pancreas_region), size=1)+
scale_color_manual(values =c("#C04140", "#6DA567", "#8AA9D6")) + #comment this line out if you want to use R's auto-color palette
scale_fill_manual(values=c("Head" = "#C04140", "Body" = "#6DA567", "Tail" = "#8AA9D6")) + #comment this line out if you want to use R's auto-color palette
theme_few() +
ylab("Ki67+ cells (%)") +
xlab("Age (years)") +
labs(color = "Pancreas region") +
# replace none with the following to add the legend back into the figure: c(.785,.90)
theme(legend.position = "none",legend.text=element_text(size=18, face="bold", family="Arial"), legend.title=element_text(size=20, face="bold", family="Arial"),
axis.text=element_text(size=22, color="black", family="Arial"), axis.title=element_text(size=24, face="bold", family="Arial", color="black"), axis.ticks=element_line(color="black"),
panel.border = element_rect(color = "black"))
ESM_Fig3
#ggsave("ESM_Fig3.png", dpi = 600)
save_plot("ESM_Fig3.tiff", ESM_Fig3, dpi=600, base_aspect_ratio=1.5)
Exploratory look at insulin vs. cd45, as requested by reviewer, but image or analysis not presented in paper. Since none of these CD45+ cells were observed to be in direct proximity to insulin positive cells, this comparison is difficult to interpret without additional data to determine if these CD45+ cells are resident or trafficking cells.
boxplot <- read_csv("cd45_insulin.csv", col_names = TRUE)
boxplot %<>% mutate(pancreas_region = ifelse(Region == "A", "Head",
ifelse(Region == "B", "Body",
"Tail")))
# for reordering the columns
boxplot <- within(boxplot,pancreas_region <- factor(pancreas_region,
levels=rev(c("Tail",
"Body",
"Head"))))
#Instead of plotting all the points directly over A, B, or C (all together as one blob); this code offsets it so that they are plotted directly over their respective boxplots
boxplot$Region_n[boxplot$Region == "A"]<-1
boxplot$Region_n[boxplot$Region == "B"]<-2
boxplot$Region_n[boxplot$Region == "C"]<-3
boxplot$Stain_adj[boxplot$Stain == "CD45"]<- -0.20
boxplot$Stain_adj[boxplot$Stain == "Insulin"]<- 0.20
#boxplots defaults used, i.e. box represents IQR, whiskers 1.5*IQR, beyond whiskers are outliers, and line within box is the median.
p3<-ggplot(boxplot, aes(pancreas_region,Positive_cells_percentage,fill=Stain)) +
geom_boxplot(outlier.size=3, fill=NA, alpha=0.5, show.legend=FALSE, aes(fill=Stain, color=Stain)) +
geom_jitter(aes(Region_n + Stain_adj,Positive_cells_percentage, color=Stain),
position=position_jitter(width=0.1,height=0),
alpha=0.5,
size=3,
show.legend=FALSE)+
xlab("Pancreas region") +
ylab("Positive cells (%)") +
theme(axis.title = element_text(size=24,color='black', family="Arial", face="bold"),
axis.text = element_text(size=22,color='black', family="Arial"),
axis.ticks=element_line(color="black"))+
panel_border(colour = "black", size = 0.5, linetype = 1, remove = FALSE)
p3