daqana / tikzDevice

A R package for producing graphics output as PGF/TikZ code for use in TeX documents.
https://daqana.github.io/tikzDevice
132 stars 26 forks source link

Plot legend size too small for text to fit #216

Open hugotomasf opened 2 years ago

hugotomasf commented 2 years ago

When the plot is generated as an image in RStudio, the legend text fits perfectly but when exported to TikZ the legend size is too small to fit. Here is the plot generated by R: Rplot1 This is the TikZ image generated in a latex document: Screenshot from 2022-06-17 18-46-49 Changing the width of the export does not fix the problem: Screenshot from 2022-06-17 18-46-00

Here is the R code:

library(tikzDevice)

set.seed(10) 
tikz('prueba.tex', width = 3, height = 3)

colores = c("blue", "red", "green", "purple", "orange")

x = runif(5, min = 10, max = 17)
y = 3000*x + 30000
plot(x, y, 
     xlab = "Educación (Años)",
     pch = 20,
     col = colores, 
     ylab = "Renta (€)",
     xlim=c(10, 17),
     ylim=c(3000*10 + 30000,3000*17 + 30000),
     bty = "L")

legend(x = "bottomright",
       legend = c("Ciudad 1", "Ciudad 2", "Ciudad 3", "Ciudad 4", "Ciudad 5"),
       pch = c(20,20,20,20,20),
       col = colores)

dev.off()

Thanks.

rstub commented 2 years ago

I get a different result when processing with tikz(..., standAlone = TRUE):

image

Note that the default Latin Modern font is used in my example. This is also the font whose metrics have been used to place the glyphs. You are using a different font in the final processing, but you are not telling tikzDevice about it. You need to add the required font packages to the preamble used by tikzDevice see section 2.1 in the tikzDevice vignette, in particular the options tikzLatexPackages, tikzXelatexPackages and tikzLualatexPackages.