I am running into an error when I try to stitch together a bar plot and point plot using cowplot. I can try to put together a working example if requested, but I thought I'd first just see if anyone could spot an obvious problem.
The code and resulting plot for the bar plot is as follows:
dodge=position_dodge(width=0.9)
pbar <- ggplot(data = dat,aes(x=npnts,y=power,fill=PrpSurvPerYr)) +
geom_bar(aes(fill=PrpSurvPerYr),stat="identity",colour="black",position=dodge) +
geom_hline(yintercept=80,linetype="dotted",size=1) +
ylab("Power") + xlab("Number of points per transect") +
scale_fill_manual(values = c("white","gray","black")) +
scale_y_continuous(breaks=seq(0,100,by=20)) +
theme(axis.text.x=element_text(size=20)) +
theme(axis.text.y=element_text(size=20)) +
theme(axis.title.x=element_text(size=30)) +
theme(axis.title.y=element_text(size=30)) +
geom_text(aes(label=ntrns),vjust=-0.3,size=8,position=dodge)+
labs(fill="% transects \nsurveyed \nper year") +
theme(legend.title=element_text(size=20)) +
theme(legend.text=element_text(size=18))
The code and resulting plot for the point plot is as follows:
ptrd <- ggplot(data = dat.plt,aes(x=X,y=med)) +
geom_point(size=3,alpha=0.3) +
geom_errorbar(aes(ymin=lo,ymax=hi),width=0.003,alpha=0.3) +
geom_hline(yintercept=0.98,linetype="dotted") +
scale_y_continuous(breaks=c(0.98)) +
scale_x_continuous(breaks=c()) +
ylab(expression(hat(lambda)[psi])) + xlab(NULL) +
theme(axis.text.x=element_blank()) +
theme(axis.title.x=element_blank()) +
theme(axis.title.y=element_text(size=35)) +
theme(axis.text.y=element_text(size=26))
Point plot I tried to stitch the two together with the following:
p <- ggdraw() +
draw_plot(pbar, x = 0, y = 0, width = 1, height = .0.75) +
draw_plot(ptrd, x = 0, y = 0.75, width = 1, height = .25)
Unfortunately, I get an error regarding an "unknown constant" and I can't even get a good look at the error because it is followed by a ton of output that overloads the allowable console space.
Any ideas would be appreciated.