daqana / tikzDevice

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

TikZ device not converting colorbar from R to TikZ #180

Closed murych closed 5 years ago

murych commented 6 years ago

Trying to plot some lines, that differs from each other by Uf parameter. R creates a colorbar of Uf values, but TikZ device doesn't convert it to TikZ format. Instead it creates a rectangle and put \pgfimage inside of it (example below).

Sample data:

Uf,d,Re,Cd,Up
1000,0.100,1.59E+05,1.51E-04,21.29
1000,0.104,1.59E+05,1.51E-04,20.87
1000,0.108,1.59E+05,1.51E-04,20.48

R code for plotting:

data_d <- read.csv('up_d.csv')

tikz(file = "3_2.tex", width = 6, height = 3)

ggplot(data = data, aes(x = d, y = Up, group = Uf)) +
  geom_line(aes(color = Uf)) +
  theme(plot.title = element_text(size = rel(1), vjust = 0), 
        axis.title = element_text(size = rel(0.8)),
        axis.title.y = element_text( vjust=3 ),
        axis.title.x = element_text( vjust=-0.5 ))

print(plot)
dev.off()

R plot sample
R plot

Part of TikZ file, containing problematic code

\path[fill=fillColor] (381.08, 72.27) rectangle (428.12,167.11);
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (433.62,216.81);
\node[inner sep=0pt,outer sep=0pt,anchor=south west,rotate=  0.00] at (386.77,  77.96) {
    \pgfimage[width= 14.45pt,height= 72.27pt,interpolate=true]{3_2_ras1}
    };
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (433.62,216.81);
\definecolor{drawColor}{RGB}{0,0,0}

XeTeX output

errors:
3_1.tex:2306: Missing $ inserted. [...ght= 72.27pt,interpolate=true]{3_2_ras1}]
3_1.tex:2306: Double subscript. [...ght= 72.27pt,interpolate=true]{3_2_ras1}]
3_1.tex:2306: Extra }, or forgotten $. [...ght= 72.27pt,interpolate=true]{3_2_ras1}]
3_1.tex:2306: Missing $ inserted. [...ght= 72.27pt,interpolate=true]{3_2_ras1}]
3_1.tex:2306: Missing } inserted. [...ght= 72.27pt,interpolate=true]{3_2_ras1}]

warnings:
3_1.tex:2306: Package pgf Warning: File "3_2_ras1" not found when defining image "pgflastimage". Tried all extensions in ".pdf:.jpg:.jpeg:.png:.bmp:" on input line 2306.

XeTeX plot result (tweaked axis labels a bit to use this plot in my course work)
LaTeX plot

krlmlr commented 6 years ago

The \pgfimage looks correct, tikzDevice should have created a file with the name 3_2_ras1.png. Maybe it ended up in the wrong directory?

bellackn commented 5 years ago

Hi @murych, I am not able to reproduce this error with the code and example data you provided. However, I could observe the same errors when I deleted the 3_2_ras1.png file that @krlmlr mentioned. Please check if this file lies in the same folder as the 3_2.tex.

murych commented 5 years ago

Seem like I haven't noticed 3_2_ras1.png in project directory. @krlmlr , @bellackn thanks for pointing out my mistake. I am really sorry about replying for too long.