r - multiple-levels grouped bar graph -


it facet_wrap plot 2 grouped bar graphs. had questions , code attached in text below.

enter image description here

q1: how annotate triple asterisks @ designated positions (better can locate position automatically without calculation/specification) drawn in plot? tried did not work:

ann_text1=data.frame(ligand=c(2), uptake=c(24), kd=factor("p", levels=c("p","q"))) tp=t+geom_text(data=ann_text1,label="***", size=8) 

q2: how use greek letter (beta) in strip title? tried integrate expression argument in labels = did not work.

t$cell=factor(t$cell, levels = unique(t$cell), labels = c("wt","beta-dko")) 

here complete version of code tried. please navigate input file through link.

library(ggplot2) library(hmisc) library(gridextra) library(grid)  t=read.csv(file.choose(), header = true) t$ligand = factor(t$ligand, levels = unique(t$ligand)) t$kd=factor(t$kd, levels = unique(t$kd)) t$cell=factor(t$cell, levels = unique(t$cell), labels = c("wt","beta-dko"))  tbar=ggplot(t, aes(kd, uptake, fill=ligand)) +   stat_summary(fun.y = mean, geom = "bar", position="dodge", color = "black", size=0.3, width = 0.6) +   stat_summary(fun.data = mean_se, geom = "errorbar", position = position_dodge(width = 0.6), size=0.3, width = .2) +   scale_fill_manual(name="ligand", labels=c("-l", "+l"), values=c("gray20", "gray80"))+   theme_bw()+   scale_y_continuous(expand = c(0,0), limit = c(0, 120), breaks = seq(0, 110, 20))+   ylab("% of t")+   facet_wrap(~cell, nrow=1)+   theme(legend.direction="horizontal",legend.position=c(0.88,0.92))+   theme(legend.text=element_text(size=9))+   theme(legend.key.size=unit(0.25,"cm")) 

you can add stat_summary(geom="text") per thread: annotation above bars:

library(ggplot2) library(hmisc) library(gridextra) library(grid)  t=read.csv("https://dl.dropboxusercontent.com/u/1204710/test.csv", header = true) t$ligand = factor(t$ligand, levels = unique(t$ligand)) t$kd=factor(t$kd, levels = unique(t$kd)) t$cell=factor(t$cell, levels = unique(t$cell), labels = c("wt","beta-dko")) ## parametrise dodging width; add vertical shift '***' label width <- 0.6 vshift <- 5 dodgewidth <- position_dodge(width=width) ## identify bars '***' label has placed using factor t$mylabel <- "" t$mylabel[with(t, ligand=="y" & cell=="wt" & kd=="p")] <- "***" t$mylabel[with(t, ligand=="y" & cell=="beta-dko" & kd=="q")] <- "***" t$mylabel <- factor(t$mylabel)  tbar <- ggplot(t, aes(kd, uptake, fill=ligand)) +     stat_summary(fun.y = mean, geom = "bar", position="dodge", color = "black", size=0.3, width = width) +     stat_summary(fun.y = function(v) mean(v)+vshift, geom = "text", position=dodgewidth, aes(label=mylabel)) +     stat_summary(fun.data = mean_se, geom = "errorbar", position = position_dodge(width = width), size=0.3, width = .2) +     scale_fill_manual(name="ligand", labels=c("-l", "+l"), values=c("gray20", "gray80"))+     theme_bw()+     scale_y_continuous(expand = c(0,0), limit = c(0, 120), breaks = seq(0, 110, 20))+     ylab("% of t")+     facet_wrap(~cell, nrow=1)+     theme(legend.direction="horizontal",legend.position=c(0.88,0.92))+     theme(legend.text=element_text(size=9))+             theme(legend.key.size=unit(0.25,"cm"))  print(tbar) 

Comments