I want to compare the data between to labeled groups, using box plots and density plots. I made a function for that, to make it easier ust entering the data I need and what feature I would like to use, and what is the label of the two groups (y
would be a binary feature):
density_and_boxplot = function(data = data, metadata = metadata, cell.type = 'cell.type', y = c()) {
combination = merge(data, metadata, by=0, all=TRUE) %>% na.omit()
p1 = ggplot(data = combination, aes(x= cell.type, fill=as.factor(y))) + geom_boxplot() + coord_flip() + title(paste('Box plot of',cell.type))
p2 = ggplot(data = combination, aes(x= cell.type, fill=as.factor(y))) + geom_density(alpha=.5) + title(paste('Distribtuion of',cell.type))
return(cowplot::plot_grid(p1,p2))
}
Calling the function:
density_and_boxplot(data = scores, metadata = mydata, cell.type = 'B-cells', y = 'PD')
I get empty plots, why is this happening?