-1

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))

Bar plot

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.

  • 1
    Can you please make this _minimal_ and _reproducible_? First, share a bit of your data for the plots (`dat` and `dat.plt`), perhaps not all of it but enough to reproduce the error. Then remove all the stuff from the plots that is not required for the error to appear (like labels and theme settings). Also have a look here: [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269) – Axeman Oct 20 '16 at 16:33

1 Answers1

0

Well, I started the process of generating a reproducible example, and found the error in my script: I have a ".0.75" for 'height' in the first 'draw_plot' command.

Guess I just need to stop being lazy and go through the process of generating a reproducible example before posting. That is probably the step where most of these kinds of errors are caught. Sorry for wasting your attention and time.