问题
I am trying to set the font size in a Cairo device, but the pointsize
argument seems to set the size of the points in the plot, and not the font size. I have this MWE:
\documentclass{article}
\begin{document}
<<setup>>=
library(maptools)
data(meuse)
coordinates(meuse) <- c("x", "y")
proj4string(meuse) <- CRS("+init=epsg:28992")
@
<<fig1, dev='cairo_pdf', dev.args=list(family ="CMU Serif", pointsize=12), fig.keep='last'>>=
plot(meuse, pch=16)
legend("topleft", "Example Text")
@
<<fig2, dev='cairo_png',fig.ext='png',dev.args=list(family ="CMU Serif", pointsize=2), fig.keep='last'>>=
plot(meuse, pch=16)
legend("topleft", "Example Text")
@
\end{document}
fig1
has large points and normal text, and fig2
has identical text but tiny points.


回答1:
In R base graphics, the font size is usually set via the argument cex(.something)
. In this specific case, you can use the cex
argument of the legend()
function, e.g.
plot(meuse, pch=16)
legend("topleft", "Example Text", cex=2)
来源:https://stackoverflow.com/questions/16880627/cairo-font-size-in-knitr