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

Measuring dimensions of \char100 takes long time #165

Closed neunzehnachtneun closed 6 years ago

neunzehnachtneun commented 7 years ago

Hei! First of all, thank you for spending so much time in this useful package! In the last few days I found a problem and as I don't know, if it is caused by this package or anything else, I submit this issue.

here is some rough example code:

## load packages
library(reshape2)
library(ggplot2) # visualization
library(ggsci) # color range
library(tikzDevice) # plot as tikz

## example dataset
x.axis <- seq(from = -180, to = 179, length.out = 192)
y.axis <- seq(from = 0, to = 90, length.out = 48)
mat <- matrix(rnorm(n = 192*48, mean = 0, sd = 1), nrow = 192, ncol = 48)
dimnames(mat) <- list(x.axis, y.axis)

## example plot with standard tool
image(x.axis, y.axis, mat)

## reshape dataframe and format as tibble
mat.molten <- melt(mat, varnames = c("lon", "lat"), value.name = "uv")
tb.mat.molten <- dplyr::as_tibble(mat.molten)

# example plot with ggplot
ggp.test <-
  ggplot(data = tb.mat.molten,
         mapping = aes(x = lon, y = lat, fill = uv)) +
  geom_tile() + scale_fill_gsea(name = "$\\sqrt(u^2+v^2)$") +
  scale_x_continuous(name = "Längengrad",
                     breaks = c(-180, -135, -90, -45, 0, 45, 90, 135, 180)) +
  scale_y_continuous(name = "Breitengrad",
                     breaks = c(0, 30, 60, 90)) +
  ggtitle("Zonales Windfeld und Position der meridionalen Zonalwindmaxima und des absoluten Chebyshev-Maximums") +
  coord_fixed(xlim = c(-180,180), ylim = c(0,90))

## Save plot as pdf
ggsave(filename = paste0("test.pdf"),
       plot = ggp.test, device = pdf, path = "./",
       dpi = 600, width = 297, height = 210, units = "mm")

## save plot as tikz / tex ## here is a problem!
#
filepath <- paste0("./test.tex")
tikz(file = filepath, pointsize = 11)
print(ggp.test)
dev.off()

In the last steps, while the code should save the plot as tikz, it freezes with:

Measuring dimensions of: \char100

Does anyone have a idea?

Kind and thanks, Sebastian

neunzehnachtneun commented 7 years ago

Might be a R-version problem. Downgrading from 3.4.1 to 3.3.1 solves.

bellackn commented 6 years ago

I can confirm that the code you provided works with R 3.4.4 and the current tikzDevice version.

This...

# [...]

filepath <- paste0("test_output/fix_165/test.tex")
tikz(file = filepath, pointsize = 11, standAlone = TRUE, engine = "xetex")
print(ggp.test)
dev.off()

... produces this:

test

I used engine = "xetex" because of the "ä" in the xlab.

Closing this issue since it appears to be resolved. Please feel free, if this is still an issue, to leave a comment requesting this issue be reopened.