Skip to content
Permalink
c5d03d2a60
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
58 lines (52 sloc) 2.35 KB
summary.plots <- function(meta_data, file_name = "summary", environment = FALSE, width = 12, height =8, ... ) {
#first Graph
data.summary <- function(x) { #function to calculate median + sd for violin plots
mu <- mean(x)
sigma1 <- mu-sd(x)
sigma2 <- mu+sd(x)
return(c(y=mu, ymin=sigma1, ymax=sigma2))
}
### 1. ###################### Boxplots(gender, age) ~ status
firstGraph <- ggplot(organ_metadata, aes(x = gender, y = age/365)) +
geom_boxplot(data = organ_metadata, aes(color = status)) +
xlab("Status") +
ylab("Age") +
scale_color_manual(values = c ("deepskyblue2", "brown3"))
### 2. ############## Barplot(gender) ~ group status
secondGraph <- ggplot(organ_metadata, aes(x = gender)) + #plot age vs expression
geom_bar(data = organ_metadata, aes(fill = status), position = position_dodge()) +
scale_fill_manual(values = c("deepskyblue2", "brown3")) #group and diagnsosis as factors
### 3. ################# Violingplots(Diagnosis, Age) with Mean and SD
if (nlevels(organ_metadata$diagnosis) > 8) {
coloursDiagnosis <- "Paired"
}
else {
coloursDiagnosis <- "Dark2"
}
thirdGraph <- ggplot(organ_metadata, aes(x = diagnosis, y = age/365, color = diagnosis)) + #plot age vs expression
geom_violin() +
geom_jitter(size = 0.4, width = 0.15) +
stat_summary(fun.data = data.summary, color = "black") +
xlab("Diagnosis") +
ylab("Age") +
labs(color = "Diagnosis") +
scale_color_brewer(palette = coloursDiagnosis)
## 4. ################# Barplots
xrange <- 1:nlevels(organ_metadata$diagnosis)
fourthGraph <- ggplot(organ_metadata, aes(x = as.numeric(diagnosis) - 0.15)) + #move 0.15 to left
geom_bar(position = "identity", width = 0.3) +
scale_x_continuous(breaks = c(xrange), labels = unique(organ_metadata$diagnosis)) +
labs(x = "diagnosis")+
geom_bar(aes(x = as.numeric(diagnosis) + 0.15, fill = status), #move 0.15 to right
position = position_dodge(), width = 0.3) +
scale_fill_manual(values = c("deepskyblue2", "brown3")) +
theme(axis.text = element_text(size = 7.5)) +
facet_wrap(~gender)
if(environment == TRUE) {
wholeGraph <- list(firstGraph, secondGraph, thirdGraph, fourthGraph)
return(wholeGraph)
}
pdf(paste0(file_name, ".pdf"), width = width, height = height)
grid.arrange(firstGraph, secondGraph, thirdGraph, fourthGraph)
dev.off()
}