Knitr - captions in the image above

Is there a way in knitr to move fig.cap over a figure? I need them to be higher, so when the shape list hyperlink is selected for a specific table, it moves to the shape. Right now, the signature and therefore the hyperlink are at the bottom, so when only the title is displayed at the top of the page, you need to scroll up to see the figure ... pretty stupid.

An example of my current code:

<<Race, fig.lp='fig:', fig=TRUE, eval=TRUE, echo=FALSE, dev='png', fig.pos='H', fig.width=8, fig.height=4, fig.cap='Race', fig.align='center', dpi=300>>= b <- ggplot(melt(race.plot, id=c("Type"), variable.name="Race", value.name="Count")) b + geom_bar(aes(Race, y=Count, fill=Race), position="dodge", stat="identity", alpha=0.7) + ggtitle("Race") + xlab("") + ylab("Count") + facet_wrap(~Type, nrow=2, scale="free_y") + theme(plot.title=element_text(size=25), axis.title=element_text(size=15), axis.text.y=element_text(size=10), axis.text.x=element_blank(), axis.ticks.x=element_blank()) @ 

I understand that there are ways to do this using latex and leaving fig.cap in poker knitr:

 \begin{figure} \caption{This is a caption above the figure} <<a-plot, echo=FALSE>>= plot(1) @ \end{figure} 

Most of the proposals should be made higher, but the date is around 2012 or early 2013. I wonder if any changes to knitr can enable this function now.

I used options in knitr and xtable to control most of the things in my output, but what is consensus? Should I avoid this and use latex options outside the pieces of the blacksmith when possible?

+6
source share
1 answer

It may be too late, but I think Yihui answered that.

You can change the knit hook for all the shapes so that the inscription is inscribed. For example, here is a version of a piece from a .Rmd document. If you say knitr to change the parameter for the shape so that the document looks first and then actual.

 ```{r setup} library(knitr) knit_hooks$set(plot = function(x, options) { paste('<figure><figcaption>', options$fig.cap, '</figcaption><img src="', opts_knit$get('base.url'), paste(x, collapse = '.'), '"></figure>', sep = '') }) ``` 
+2
source

All Articles