With the same data I followed a four step approach.
First: subsetting the data
open <- subset(data1, Physicians_Out == "Open")
restr <- subset(data1, Physicians_Out == "Restricted")
closed <- subset(data1, Physicians_Out == "Closed")
Second: creating the labels for the different subsets
labs.open <- paste(gsub("/","-
",names(table(open$Physicians_In)),fixed=T),
"
(N=",table(open$Physicians_In),")",sep="")
labs.restr <- paste(gsub("/","-
",names(table(restr$Physicians_In)),fixed=T),
"
(N=",table(restr$Physicians_In),")",sep="")
labs.closed <- paste(gsub("/","-
",names(table(closed$Physicians_In)),fixed=T),
"
(N=",table(closed$Physicians_In),")",sep="")
Third: creating a theme for removing the y-axis labels & text for the 2nd & 3rd sub-graphs
mytheme <- theme(
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()
)
Finally: creating the graph
p1 <- ggplot(open,aes(x=Physicians_In,y=share,fill=Physicians_In)) +
geom_boxplot() + stat_sum_single(mean) +
geom_jitter(position = position_jitter(width = .2),color="blue") +
guides(fill=FALSE) +
ggtitle(paste("Physician Access (Out): Open
N = (", nrow(open), ")
")) +
scale_y_continuous("Gammagard Share",labels=percent) +
scale_x_discrete("
Physician Access (In Hospital)",labels=labs.open) +
theme_bw()
p2 <- ggplot(restr,aes(x=Physicians_In,y=share,fill=Physicians_In)) +
geom_boxplot() + stat_sum_single(mean) +
geom_jitter(position = position_jitter(width = .2),color="blue") +
guides(fill=FALSE) +
ggtitle(paste("Physician Access (Out): Restricted
N = (", nrow(restr), ")
")) +
scale_x_discrete("
Physician Access (In Hospital)",labels=labs.restr) +
theme_bw() + mytheme
p3 <- ggplot(closed,aes(x=Physicians_In,y=share,fill=Physicians_In)) +
geom_boxplot() + stat_sum_single(mean) +
geom_jitter(position = position_jitter(width = .2),color="blue") +
guides(fill=FALSE) +
ggtitle(paste("Physician Access (Out): Closed
N = (", nrow(closed), ")
")) +
scale_x_discrete("
Physician Access (In Hospital)",labels=labs.closed) +
theme_bw() + mytheme
library(gridExtra)
grid.arrange(p1, p2, p3, ncol=3)
Which gives the following result: