Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot legend size too small for text to fit #216

Open
hugotomasf opened this issue Jun 17, 2022 · 1 comment
Open

Plot legend size too small for text to fit #216

hugotomasf opened this issue Jun 17, 2022 · 1 comment

Comments

@hugotomasf
Copy link

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
Copy link
Member

rstub commented Jul 24, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants