Invisible linetypes in in pdf

47 views
Skip to first unread message

Michel

unread,
Dec 7, 2009, 7:08:44 AM12/7/09
to ggplot2
Hi all,

I'm having a weird problem with linetypes. When I plot data with five
lines (different linetypes), and plot it to pdf, one of the linetypes
is somehow invisible, e.g.:

dat = data.frame(a=1:100,b=rep(1:5,each = 20))

pdf('test2.pdf',width=7,height=4)
ggplot(data=dat) + geom_line(aes(1:20,a,linetype=factor(b)))
dev.off()

the fifth linetype is invisible in the pdf (but not on the screen with
quartz). I also tried the following variations:

(1) + scale_linetype_manual(values = c(1,2,3,4,5))
(2) + scale_linetype_manual(values = c(1,2,3,4,6))
(3) + scale_linetype_manual(values = c(6,7,8,9,10))

Surprisingly, the linetypes are not even consistent (i.e., in (1) and
(2) the first 4 lines do not have the same type in the plot), but also
with any of these options there is *always* one of the five lines that
is invisible...

does anyone have a clue how to solve this weird issue?

Thank you very much!
Michel

JiHO

unread,
Dec 7, 2009, 8:13:30 AM12/7/09
to Michel, ggplot2
On Mon, Dec 7, 2009 at 13:08, Michel <michel.m...@gmail.com> wrote:
> does anyone have a clue how to solve this weird issue?

that's a bug in the pdf() device of R I think. It has come up quite a
few times on this list already. try using quartz(type="pdf") instead.

JiHO
---
http://maururu.net

JiHO

unread,
Dec 7, 2009, 10:29:11 AM12/7/09
to Michel Meulpolder, ggplot2
Remember to reply all so that other people on the list can see your posts.

On Mon, Dec 7, 2009 at 15:19, Michel Meulpolder
<michel.m...@gmail.com> wrote:
> Thanks for the answer. However, when I try quartz(type="pdf") with a dataset
> of many points, I get linetypes show inconsistent behavior (i.e., some parts
> of dotted lines become continuous). My hypothesis is that quartz/ggplot
> connects every two succeeding points with a 'new' line, and therefore points
> too close together do not exhibit a clear line pattern.

well, that's very strange. Does it also look like that on screen when
you plot it? I thought quartz() was pretty immune to this. What you
could do is:
- try ggsave but I am afraid it won't do better
- try copying from the screen (select your plot window and hit ⌘C)
then paste into preview (in Preview: File > New from Clipboard). This
creates a PDF which should be exactly what you have on screen. Un
fortunately it is not automated
- install Cairo and try the CairoPDF device

JiHO
---
http://maururu.net

Michel Meulpolder

unread,
Dec 7, 2009, 10:49:08 AM12/7/09
to JiHO, ggplot2

On Mon, Dec 7, 2009 at 15:19, Michel Meulpolder
> Thanks for the answer. However, when I try quartz(type="pdf") with a dataset
> of many points, I get linetypes show inconsistent behavior (i.e., some parts
> of dotted lines become continuous). My hypothesis is that quartz/ggplot
> connects every two succeeding points with a 'new' line, and therefore points
> too close together do not exhibit a clear line pattern.

well, that's very strange. Does it also look like that on screen when
you plot it? I thought quartz() was pretty immune to this.

It looks exactly the same on screen.
 
What you
could do is:
- try ggsave but I am afraid it won't do better
- try copying from the screen (select your plot window and hit ⌘C)
then paste into preview (in Preview: File > New from Clipboard). This
creates a PDF which should be exactly what you have on screen. Un
fortunately it is not automated
- install Cairo and try the CairoPDF device

Since copy-pasting gives the same result, I guess the last option you mention is the only thing I can try. However, I'm still very puzzled by this, since I would not expect such a simple scenario to give problems... :)

Anyhow, any other tips are more than welcome.
Thanks so far!

Michel

baptiste auguie

unread,
Dec 7, 2009, 11:32:35 AM12/7/09
to Michel Meulpolder, ggplot2
Hi,

I can confirm the pdf problem (even with R-dev), but quartz() works
for me. Could you post a minimal example where you see "inconsistent
behavior"?

Yet another option is the tikzDevice package, which produces a pdf
through latex.

HTH,

baptiste
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> To post to this group, send email to ggp...@googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2

baptiste auguie

unread,
Dec 8, 2009, 5:16:43 AM12/8/09
to Michel Meulpolder, ggplot2
Hi,

Very strange. I tested you example with R 2.10 and 2.11 and I can't
reproduce your problem with either quartz() or pdf(). Maybe you should
update R if you're using an older version.

sessionInfo()
R version 2.10.0 (2009-10-26)
i386-apple-darwin9.8.0

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base

other attached packages:
[1] ggplot2_0.8.3 reshape_0.8.3 plyr_0.1.9 proto_0.3-8

HTH,

baptiste

On Tue, Dec 8, 2009 at 8:52 AM, Michel Meulpolder
<michel.m...@gmail.com> wrote:
>> I can confirm the pdf problem (even with R-dev), but quartz() works
>> for me. Could you post a minimal example where you see "inconsistent
>> behavior"?
>
> See the following example. Due to the log axis the data points become denser
> to the right. On my screen, the dashed linetype starts out dashed, but
> gradually becomes solid (see also attachment).
> a = 1:10000
> ggplot() + geom_line(aes(a,a,linetype="a")) + geom_line(aes(a,1000 +
> a*2,linetype="b")) + scale_x_log10()
> Thanks,
> Michel

baptiste auguie

unread,
Dec 8, 2009, 7:32:34 AM12/8/09
to Michel Meulpolder, ggplot2
Hi,

I can confirm the problem with both R 2.10 and 2.11. I suggest you
file a bug report to R-devel (be sure to check carefully how to do
it), it's probably a bug in quartz().

Best,

baptiste

On Tue, Dec 8, 2009 at 1:12 PM, Michel Meulpolder
<michel.m...@gmail.com> wrote:
> Hi,
> Updating from 2.9 to 2.10 seemed to solve the issue... but things get
> weirder, since the phenomenon does still occur when there are yet more
> points:
> a = 1:20000
> gplot() + geom_line(aes(a,a,linetype="a")) + geom_line(aes(a,1000
> + a*2,linetype="b")) + scale_x_log10()
> As our versions are now the same: do you with this example also get the
> incorrect dashed line?
> Thanks so far!
> Michel

Michel Meulpolder

unread,
Dec 8, 2009, 7:12:19 AM12/8/09
to baptiste auguie, ggplot2
Hi,
Updating from 2.9 to 2.10 seemed to solve the issue... but things get weirder, since the phenomenon does still occur when there are yet more points:

a = 1:20000

gplot() + geom_line(aes(a,a,linetype="a")) + geom_line(aes(a,1000 + a*2,linetype="b")) + scale_x_log10()
As our versions are now the same: do you with this example also get the incorrect dashed line?

Thanks so far!
Michel


On Tue, Dec 8, 2009 at 11:16 AM, baptiste auguie <bapt...@googlemail.com> wrote:

Michel Meulpolder

unread,
Dec 8, 2009, 2:52:32 AM12/8/09
to baptiste auguie, ggplot2
I can confirm the pdf problem (even with R-dev), but quartz() works
for me. Could you post a minimal example where you see "inconsistent
behavior"?

See the following example. Due to the log axis the data points become denser to the right. On my screen, the dashed linetype starts out dashed, but gradually becomes solid (see also attachment).

a = 1:10000
ggplot() + geom_line(aes(a,a,linetype="a")) + geom_line(aes(a,1000 + a*2,linetype="b")) + scale_x_log10()

Thanks,
Michel



Rplot.pdf

Michel Meulpolder

unread,
Dec 8, 2009, 2:43:20 PM12/8/09
to baptiste auguie, ggplot2
Hi,

Yes, it looks like I have no other option...
Thanks for all help!

Best,
Michel

baptiste auguie

unread,
Dec 8, 2009, 3:28:41 PM12/8/09
to Michel Meulpolder, ggplot2
Hi,

if you do send a bug report you might want to make it clear that it's
not related to ggplot2 by providing a raw Grid example,

x = seq(0, 10, length=10000)
y = cos(x)

pdf("test-pdf.pdf", width=4, height=4)
pushViewport(viewport(xscale=c(0, 10), yscale=c(0, 6)))
for(ind in 1:5)
grid.lines(x, y+ind, gp=gpar(lty=ind), default.units="native")
dev.off()

quartz(type="pdf", file="test-quartz.pdf", width=4, height=4)
pushViewport(viewport(xscale=c(0, 10), yscale=c(0, 6)))
for(ind in 1:5)
grid.lines(x, y+ind, gp=gpar(lty=ind), default.units="native")
dev.off()


The algorithm that computes the dashed lines is clearly working better
for pdf than for quartz when the points are very dense.

I can't reproduce the disappearance of the lines in the pdf device
though, I'm wondering if it's not a ggplot2 bug?

Best,

baptiste

On Tue, Dec 8, 2009 at 8:43 PM, Michel Meulpolder
test-quartz.pdf
test-pdf.pdf

baptiste auguie

unread,
Dec 8, 2009, 4:53:17 PM12/8/09
to hadley wickham, ggplot2
Regarding the original bug (invisible lines for pdf), does anyone know
if it has been reported to the R team?

I think I nailed the problem to an unfortunate side-effect of lineend="butt",

pdf("test.pdf")
grid.newpage()
grid.lines(gp=gpar(lty="13"))
grid.newpage()
grid.lines(gp=gpar(lty="13", lineend = "butt"))
dev.off()

Illustrator recognises a line in both pages in the pdf output, however
in the second page the line pattern has zero solid length because of
the lineend.

It may be that this is the correct behavior and that quartz() actually
cheats, I don't know. From the perspective of ggplot2, it might good
to change the lineend parameter in geom_path ?


Best,

baptiste
test.pdf

hadley wickham

unread,
Dec 8, 2009, 5:04:51 PM12/8/09
to baptiste auguie, ggplot2
> It may be that this is the correct behavior and that quartz() actually
> cheats, I don't know. From the perspective of ggplot2, it might good
> to change the lineend parameter in geom_path ?

Coincidentally, I just made that user controllable:
http://github.com/hadley/ggplot2/commit/fcbbfc916110adcd8893500a1f114ca1138cbedf

Hadley

--
http://had.co.nz/

baptiste auguie

unread,
Dec 8, 2009, 5:09:31 PM12/8/09
to ggplot2
Nice, thanks!

I convinced myself that it was indeed a bug with pdf and I just sent
an email to R-devel.

baptiste

baptiste auguie

unread,
Dec 11, 2009, 9:39:09 AM12/11/09
to Michel Meulpolder, ggplot2
Hi,

I just sent two separate bug reports (PR#14128 for invisible pdf lines
and PR#14129 for colliding line patterns with quartz). The program
didn't like my email address for some reason so it's awaiting
moderator approval.

All the best,

baptiste

Michel Meulpolder

unread,
Dec 11, 2009, 10:14:21 AM12/11/09
to baptiste auguie, ggplot2
Hi,

Great, thanks :)

Best,
Michel

baptiste auguie

unread,
Jan 6, 2010, 4:42:29 AM1/6/10
to ggplot2
Hi all,

I'm not familiar with the process of reporting bugs to R core.
PR#14128 seems quite serious to me yet no-one replied publicly to the
report and for all I know it might end up forgotten in the long list
of pending reports.

Would it help if someone else joined the discussion on R-devel and
confirmed that this is indeed a serious problem with pdf output? It's
especially important to us ggplot2 users that we face the total
disappearance of a particular linetype; such an issue is less obvious
with other graphics packages that do not use the same lineend ("butt")
by default. I think consistency across devices should be more
important than the back-compatibility issue.


Thanks,

baptiste

R-bugs:
http://bugs.r-project.org/cgi-bin/R/Graphics?id=14128;user=guest

R-devel discussion:
http://markmail.org/thread/uczvziwcxga5jr3f

baptiste auguie

unread,
Jan 6, 2010, 5:08:08 AM1/6/10
to ggplot2
Whoops, ignore my previous message: I had misunderstood the R bugs
note. It seems from the svn log that the issue was fixed last
December,

------------------------------------------------------------------------
r50695 | ripley | 2009-12-09 13:37:27 +0100 (Wed, 09 Dec 2009) | 1 line

adjust line textures for butt end caps on postscript() and pdf() devices
------------------------------------------------------------------------

so we shouldn't see invisible (!) lines in ggplot2 anymore :)

Best,

baptiste

Reply all
Reply to author
Forward
0 new messages