Problems with ggsave(type = "pdf") on Mac

47 views
Skip to first unread message

Brandon Farr

unread,
Apr 3, 2009, 6:22:48 PM4/3/09
to ggplot2
This issue deals with ggsave. When using ggsave (type = "pdf") on a
Mac (see sessionInfo below), linetype = 5, or at least the fifth
linetype that ggplot chooses, gets lost in the save. The plot displays
properly onscreen in an R session, but does not display properly in
the pdf.

For an example of the pdf, see "ggsave_linetype_bug.pdf" in Files.

Thanks,
Brandon

<CODE>


# Code to illustrate missing line type 5 in legend
ctry <- rep(c("US","UK", "EU", "JP", "BR"), each = 5)
x <- (runif(25) - 1 * 5)
y <- (runif(25) - 1 * 5)

plotData <- data.frame(ctry, x, y, stringsAsFactors = FALSE)
sapply(plotData, class)


p1 <- qplot(x, y, data = plotData, geom="line", linetype = ctry)
ggsave(filename = "test.pdf", plot = p1)

# > sessionInfo()
# R version 2.8.1 (2008-12-22)
# i386-apple-darwin8.11.1
#
# locale:
# en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
#
# attached base packages:
# [1] grid stats graphics grDevices utils datasets
# [7] methods base
#
# other attached packages:
# [1] ggplot2_0.8.2 reshape_0.8.2 plyr_0.1.4 proto_0.3-8

Mike Lawrence

unread,
Apr 4, 2009, 9:53:00 AM4/4/09
to Brandon Farr, ggplot2
This also occurs with pdf():

pdf('test2.pdf',5,5)
p1
dev.off()
--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tinyurl.com/mikes-public-calendar

~ Certainty is folly... I think. ~

hadley wickham

unread,
Apr 4, 2009, 6:43:23 PM4/4/09
to Mike Lawrence, Brandon Farr, ggplot2
Hmmm, strange. It looks like it might be a bug with the pdf output on
a mac. Can anyone confirm that this happens on other platform as
well?

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

Mike Lawrence

unread,
Apr 4, 2009, 8:24:21 PM4/4/09
to hadley wickham, Brandon Farr, ggplot2
This *does* work on a mac:

pdf('test3.pdf',5,5)
plot(1:10,type='l',lty=5)
dev.off()

Rainer Hurling

unread,
Apr 5, 2009, 3:47:39 AM4/5/09
to hadley wickham, Mike Lawrence, Brandon Farr, ggplot2
On FreeBSD 8.0-CURRENT with R version 2.9.0 alpha (2009-03-29 r48242)
all five lines are plotted.

In the pdf file line type 5 is very very small on the main graphics and
not as small on the legend. So perhaps it exists on Mac and only is to
small to regocnize it?

Rainer Hurling

Brandon Farr

unread,
Apr 8, 2009, 9:35:44 AM4/8/09
to ggplot2
It could be that it is too small. I tried the same code, only
substituting the following:

p1 <- qplot(x, y, data = plotData, geom="line", linetype = ctry, size
= I(1))
ggsave(filename = "test.pdf", plot = p1)

The same problem occurs.

-Brandon



On Apr 5, 3:47 am, Rainer Hurling <rhur...@gwdg.de> wrote:
> On FreeBSD 8.0-CURRENT with R version 2.9.0 alpha (2009-03-29 r48242)
> all five lines are plotted.
>
> In the pdf file line type 5 is very very small on the main graphics and
> not as small on the legend. So perhaps it exists on Mac and only is to
> small to regocnize it?
>
> Rainer Hurling
>
> On 05.04.2009 00:43 (UTC+1), hadley wickham wrote:
>
> > Hmmm, strange.  It looks like it might be a bug with the pdf output on
> > a mac.  Can anyone confirm that this happens on other platform as
> > well?
>
> > Hadley
>
> > On Sat, Apr 4, 2009 at 8:53 AM, Mike Lawrence <Mike.Lawre...@dal.ca> wrote:
> >> This also occurs with pdf():
>
> >> pdf('test2.pdf',5,5)
> >> p1
> >> dev.off()
>

Brandon Farr

unread,
Apr 8, 2009, 3:42:48 PM4/8/09
to ggplot2
Hadley,

It does appear that the problem has to do with "on stretches" of
linetypes of length = 1. They are all lost in the pdf processing on
the Mac. I have reviewed the documentation and have figured out how to
define a manual scale. However, I can't figure out how to get just a
solid line, in addition to the dot-dash lines. See below.

# This works
linetypes <- c("82", "21", "42", "44", "4424", "6363")

p1 + scale_linetype_manual(values = linetypes)

# However, the following linetypes definitions don't work
linetypes <- c(NULL, "11", "31", "33", "3313", "4242")
linetypes <- c(NA, "11", "31", "33", "3313", "4242")
linetypes <- c("00", "11", "31", "33", "3313", "4242")

p1 + scale_linetype_manual(values = linetypes)

hadley wickham

unread,
Apr 12, 2009, 12:08:40 PM4/12/09
to Brandon Farr, ggplot2
Hi Brandon,

You want "solid":

linetypes <- c("solid", "11", "31", "33", "3313", "4242")

Hadley
--
http://had.co.nz/
Reply all
Reply to author
Forward
0 new messages