Why does R redistribute everything in the plot, but not the text when exporting?

Whenever I try to export an R-graph, either with RStudio using pdf() , I find that all elements are oversized accordingly, but not text. This may cause the headers to be disabled.

Try resizing this graph in Rstudio (or use pdf("plot.pdf", width, height) in the R database):

 ggplot(data=data.frame(x=rnorm(100), y=rnorm(100)), aes(x, y)) + geom_point() + geom_text(aes(label=rep("a", 100))) + labs(y="Title that is very loooooooooooooooooooooooooooooooooooooooong") 

When width x height is 5 x 5 , the text is oversized and the title is disabled. But as 10 x 10 everything fits.

So, it seems that the text remains at a constant “size” regardless of what I specify for the plot size. Is this the correct understanding of how to export R graphics?

If so, what do you usually do to make sure that the text in the exported graphics fits?

+7
r pdf plot
source share
1 answer

Finally, I see the intuitiveness of this behavior. When I posted the question, I expect R to resize all the elements inside the graph when I resize the graph.

However, in fact, the size of all elements is fixed, including text, line, label mark, etc., and recalibration of the graph only changes the size of the graph while maintaining the relative position of the elements.

To see this, run pdf("small.pdf",5,5); plot(1,1); dev.off() and pdf("large.pdf",10,10); plot(1,1); dev.off() pdf("small.pdf",5,5); plot(1,1); dev.off() and pdf("large.pdf",10,10); plot(1,1); dev.off() pdf("small.pdf",5,5); plot(1,1); dev.off() and pdf("large.pdf",10,10); plot(1,1); dev.off() . Then, if you show two graphs, increase the scale so that the physical size on the screen is 5x5 and 10x10 , the sizes of the elements should coincide between the two graphs.

So the best practice is probably (please share your practice):

  • when building a drawing, indicate the dimensions of the elements that make sense relative to each other,
  • when exporting, select the size of the plot in which everything fits
  • import into latex using \includegraphics[width=\textwidth, height=\textheight,keepaspectratio]
+7
source share

All Articles