---
title: "size"
output: html_document
---
```{r}
library(dplyr)
library(tidyverse)
library(cowplot)
```
```{r}
setwd("P:\\PD_Diabetes\\Manuscript_1\\D30")
dataB3 <- readr::read_csv("Summary_size_B3D30.csv")
dataB1 <- readr::read_csv("Summary_size_B1D30.csv")
dataB2 <- readr::read_csv("Summary_size_B2D30.csv")
dataB4 <- readr::read_csv("Summary_size_B4D30.csv")
dataB5 <- readr::read_csv("Summary_size_B5D30.csv")
```
Batch3
```{r}
dataB3$Treatment <- factor(dataB3$Treatment, levels=c("Ctrl", "Low glucose", "Low insulin"))
dataB3$Cell_line <- factor(dataB3$Cell_line, levels=c("WT56","WT68","WT23338"))
ggplot(dataB3, aes(x=Treatment, y=Area))+
geom_boxplot(aes(fill=Treatment),width=1)+
#scale_fill_manual(values=c('DarkGray'))+ #RosyBrown
geom_jitter(aes(color=Cell_line),position=position_jitter(0.2))+
#scale_color_manual(values = c("SteelBlue","DarkGreen")) +
facet_grid(~Cell_line)+
theme_bw()+
labs(title="Organoid size", y = "Area, um")+
theme(plot.title=element_text(size=15, face="bold", hjust=0.5),
axis.text.x=element_text(size = 12, angle=45, vjust = 1, hjust = 1),
axis.title.x=element_blank(), axis.title.y=element_text(size=12)) -> p
print(p)
#ggsave('Size comparison2.png', height = 6 , width = 9)
```
Batch1
```{r}
dataB1$Treatment <- factor(dataB1$Treatment, levels=c("Ctrl", "Low glucose", "Low insulin"))
dataB1$Cell_line <- factor(dataB1$Cell_line, levels=c("WT56","WT68","WT23338"))
ggplot(dataB1, aes(x=Treatment, y=Area))+
geom_boxplot(aes(fill=Treatment),width=1)+
#scale_fill_manual(values=c('DarkGray'))+ #RosyBrown
geom_jitter(aes(color=Cell_line),position=position_jitter(0.2))+
#scale_color_manual(values = c("SteelBlue","DarkGreen")) +
facet_grid(~Cell_line)+
theme_bw()+
labs(title="Organoid size", y = "Area, um")+
theme(plot.title=element_text(size=15, face="bold", hjust=0.5),
axis.text.x=element_text(size = 12, angle=45, vjust = 1, hjust = 1),
axis.title.x=element_blank(), axis.title.y=element_text(size=12)) -> p
print(p)
#ggsave('Size comparison2.png', height = 6 , width = 9)
```
Batch4
```{r}
dataB4$Treatment <- factor(dataB4$Treatment, levels=c("Ctrl", "Low glucose", "Low insulin"))
dataB4$Cell_line <- factor(dataB4$Cell_line, levels=c("WT56","WT68","WT23338"))
ggplot(dataB4, aes(x=Treatment, y=Area))+
geom_boxplot(aes(fill=Treatment),width=1)+
#scale_fill_manual(values=c('DarkGray'))+ #RosyBrown
geom_jitter(aes(color=Cell_line),position=position_jitter(0.2))+
#scale_color_manual(values = c("SteelBlue","DarkGreen")) +
facet_grid(~Cell_line)+
theme_bw()+
labs(title="Organoid size", y = "Area, um")+
theme(plot.title=element_text(size=15, face="bold", hjust=0.5),
axis.text.x=element_text(size = 12, angle=45, vjust = 1, hjust = 1),
axis.title.x=element_blank(), axis.title.y=element_text(size=12)) -> p
print(p)
#ggsave('Size comparison2.png', height = 6 , width = 9)
```
Batch2
```{r}
dataB2$Treatment <- factor(dataB2$Treatment, levels=c("Ctrl", "Low insulin"))
dataB2$Cell_line <- factor(dataB2$Cell_line, levels=c("WT56","WT68","WT23338"))
ggplot(dataB2, aes(x=Treatment, y=Area))+
geom_boxplot(aes(fill=Treatment),width=1)+
#scale_fill_manual(values=c('DarkGray'))+ #RosyBrown
geom_jitter(aes(color=Cell_line),position=position_jitter(0.2))+
#scale_color_manual(values = c("SteelBlue","DarkGreen")) +
facet_grid(~Cell_line)+
theme_bw()+
labs(title="Organoid size", y = "Area, um")+
theme(plot.title=element_text(size=15, face="bold", hjust=0.5),
axis.text.x=element_text(size = 12, angle=45, vjust = 1, hjust = 1),
axis.title.x=element_blank(), axis.title.y=element_text(size=12)) -> p
print(p)
#ggsave('Size comparison2.png', height = 6 , width = 9)
```
Batch5
```{r}
dataB5$Treatment <- factor(dataB5$Treatment, levels=c("Ctrl", "Low insulin"))
dataB5$Cell_line <- factor(dataB5$Cell_line, levels=c("WT56","WT68","WT23338"))
ggplot(dataB5, aes(x=Treatment, y=Area))+
geom_boxplot(aes(fill=Treatment),width=1)+
#scale_fill_manual(values=c('DarkGray'))+ #RosyBrown
geom_jitter(aes(color=Cell_line),position=position_jitter(0.2))+
#scale_color_manual(values = c("SteelBlue","DarkGreen")) +
facet_grid(~Cell_line)+
theme_bw()+
labs(title="Organoid size", y = "Area, um")+
theme(plot.title=element_text(size=15, face="bold", hjust=0.5),
axis.text.x=element_text(size = 12, angle=45, vjust = 1, hjust = 1),
axis.title.x=element_blank(), axis.title.y=element_text(size=12)) -> p
print(p)
#ggsave('Size comparison2.png', height = 6 , width = 9)
```
```{r}
all<-rbind(dataB1, dataB2, dataB3, dataB4, dataB5)
```
```{r}
allIns<-subset(all, Treatment %in% c("Ctrl","Low insulin"))
allIns %>%
mutate(Condition = case_when(str_detect(Treatment, 'Ctrl') ~ 'IR', str_detect(Treatment, 'Low insulin') ~ 'IS', TRUE ~ 'test')) -> FE
FE$Condition <- factor(FE$Condition, levels=c("IR", "IS"))
ggplot(FE, aes(x=Condition, y=Area))+
geom_boxplot(aes(fill=Condition),width=0.5)+
scale_fill_manual(values=c('grey',"gold3"))+
geom_jitter(aes(color=Cell_line),position=position_jitter(0.2))+
ggpubr::stat_compare_means(comparisons = list(c("IR","IS")), test='wilcox.test', label="p.signif", vjust=0.2)+
#scale_color_manual(values = c("SteelBlue","DarkGreen")) +
#facet_grid(~Cell_line)+
theme_bw()+
labs(title="Non-embedded organoid size D30", y = "Area, um")+
theme(plot.title=element_text(size=18, face="bold", hjust=0.5),
axis.text.x=element_blank(), axis.text.y = element_text(size=14),
axis.title.x=element_blank(), axis.title.y=element_text(size=18),
legend.title=element_text(size=15),
legend.text=element_text(size=14)) -> p
print(p)
#ggsave('Size comparison2.png', height = 6 , width = 9)
```
```{r}
#write.csv(allIns, 'Size_summary_non_embedded.csv')
```
```{r}
mean56Ctrl<-subset(FE, Cell_line %in% 'WT56' & Condition %in% 'IR')
mean56Ctrl<-mean(mean56Ctrl$Area)
mean68Ctrl<-subset(FE, Cell_line %in% 'WT68' & Condition %in% 'IR')
mean68Ctrl<-mean(mean68Ctrl$Area)
mean23Ctrl<-subset(FE, Cell_line %in% 'WT23338' & Condition %in% 'IR')
mean23Ctrl<-mean(mean23Ctrl$Area)
mean56LI<-subset(FE, Cell_line %in% 'WT56' & Condition %in% 'IS')
mean56LI<-mean(mean56LI$Area)
mean68LI<-subset(FE, Cell_line %in% 'WT68' & Condition %in% 'IS')
mean68LI<-mean(mean68LI$Area)
mean23338LI<-subset(FE, Cell_line %in% 'WT23338' & Condition %in% 'IS')
mean23338LI<-mean(mean23338LI$Area)
```