Sharpie / RTikZDevice

A R package for producing graphics output as PGF/TikZ code for use in TeX documents.
31 stars 36 forks source link

Missing line width calculations #20

Closed Sharpie closed 13 years ago

Sharpie commented 13 years ago

As reported by Baptiste Auguie:

A simple plot of several lines with various thicknesses using grid graphics:

require(grid)
require(tikzDevice)

tikz('line_width.tex', standAlone = TRUE)
plot.new()
segments(0,seq(-1,1,by=0.2),1,seq(-1,1,by=0.2),lwd=seq(0.2,by=0.2,length=11))
dev.off()

Produces output with far less variation in line thickness than the lwd parameter would suggest:

\draw[color=drawColor,line cap=round,line join=round,fill opacity=0.00,] ( 65.18,  2.61) -- (464.71,  2.61);

\draw[color=drawColor,line cap=round,line join=round,fill opacity=0.00,] ( 65.18, 75.85) -- (464.71, 75.85);

\draw[color=drawColor,line cap=round,line join=round,fill opacity=0.00,] ( 65.18,149.09) -- (464.71,149.09);

\draw[color=drawColor,line cap=round,line join=round,fill opacity=0.00,] ( 65.18,222.33) -- (464.71,222.33);

\draw[color=drawColor,line cap=round,line join=round,fill opacity=0.00,] ( 65.18,295.56) -- (464.71,295.56);

\draw[color=drawColor,line width= 0.8pt,line cap=round,line join=round,fill opacity=0.00,] ( 65.18,368.80) -- (464.71,368.80);

\draw[color=drawColor,line width= 0.8pt,line cap=round,line join=round,fill opacity=0.00,] ( 65.18,442.04) -- (464.71,442.04);

The parameter values passed to TikZ_Line in plotParams->lwd are:

1.0000
1.2000
1.4000
1.6000
1.8000
2.0000
2.2000
Sharpie commented 13 years ago

At the C level, R uses pGEcontext, a pointer to a structure, to store plot information. The line width is encoded in pGEcontext->lwd which is of type double. The code in the tikzDevice responsible for calculating and printing line widths was declaring lwd to be of type int. This resulted in calculations that were either incorrect or ignored.

Sharpie commented 13 years ago

Fixed in Sharpie/RTikZDevice@082cdf8c501bf69696bff6a57ddca6caa5b1f932