0

I'm trying to build graphs in a PDF format from the output from my R script. I'm using the knit2PDF package to do this.

When I have more than one data point to plot it plots fine. Eg:When there is more than one data point

However, when there is only data point the graph looks something like thisOne data point

Here's the code im using :

 plot.new()
      par(mar=c(2,0,0,0))
      par(xpd=T, mar=par()$mar+c(0,0,0,4))
      bplot= barplot(p[c("Control","Exposed"),], col=c("#0078E8","#FF9900"),
             beside=T,names.arg=paste(paste(colnames(p),sep = " "),
                          paste("Control:", p["Control_count",], sep=" "),
                          paste("Exposed:", p["Exposed_count",], sep= " ")
                          ,sep="\n"),
             cex.names=0.4, width = 0.5, axes=F, border=F,space=c(0,1),ylim=c(0,max(p[c("Control","Exposed"),]+10)))

Is there a way I can control the look of the graph automatically when there is one data point ?

  • Specify `fig.width = ` and/or `fig.height =`? – Daniel Anderson Oct 28 '16 at 18:03
  • Thanks @DanielAnderson. But would this be dynamic in nature ? Would ideally want the chart sizes to adjust automatically based on the # of variables. – Pratyush Tallapragada Oct 28 '16 at 20:10
  • 1
    You can make it dynamic by specifying the width according to other objects you have previously created. Not sure if that's what you're wanting exactly, but it may help. See http://stackoverflow.com/questions/15365829/dynamic-height-and-width-for-knitr-plots – Daniel Anderson Oct 28 '16 at 20:13
  • @DanielAnderson - Unable to get that as a dynamic change in-spite of the additions. Here's the addition for every chunk. **<>=** Any other workarounds ? – Pratyush Tallapragada Nov 02 '16 at 21:49

0 Answers0