Using pdf() to export plot

25 views
Skip to first unread message

Etienne

unread,
Feb 4, 2009, 2:31:21 PM2/4/09
to ggplot2
Hi,

I tried to plot my graphics in a pdf, but using ggplot() left the pdf
empty.

pdf("test.pdf")
for(i in 1:3){
# I'll try to make three pages
ggplot(mtcars, aes(wt, mpg)) + geom_point()
}
dev.off()


Etienne

hadley wickham

unread,
Feb 4, 2009, 2:33:05 PM2/4/09
to Etienne, ggplot2
It's the loop: you need to explicitly print() the plot.
Hadley
--
http://had.co.nz/

baptiste auguie

unread,
Feb 4, 2009, 2:35:56 PM2/4/09
to Etienne, ggplot2
Hi,

like lattice plots, you need to explicitly call print within a loop,

try

pdf("test.pdf")
for(i in 1:3){
    p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
print(p)
}
dev.off()

baptiste


From: Etienne <Etie...@gmail.com>
To: ggplot2 <ggp...@googlegroups.com>
Sent: Wednesday, 4 February, 2009 19:31:21
Subject: Using pdf() to export plot

Etienne Bellemare Racine

unread,
Feb 4, 2009, 3:22:16 PM2/4/09
to hadley wickham, ggplot2
So simple ! Thanks. But I also want to add some text, it seems I can't use text(). print(text()) is not working this time !
pdf("test.pdf")
for(i in 1:3){
   ggplot(mtcars, aes(wt, mpg)) + geom_point()

   # problem is here
   text(1,0,labels=i)
}
dev.off()

Etienne

hadley wickham a écrit :

Mike Lawrence

unread,
Feb 4, 2009, 3:28:14 PM2/4/09
to Etienne Bellemare Racine, hadley wickham, ggplot2
See:
http://had.co.nz/ggplot2/geom_text.html
--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University
www.thatmike.com

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

~ Certainty is folly... I think. ~

Etienne Bellemare Racine

unread,
Feb 4, 2009, 3:36:52 PM2/4/09
to Mike Lawrence, hadley wickham, ggplot2
I don't understand how I can add arbitrary text (like a page number or some other information) at an arbitrary location using geom_text() could you show me an example ?

Etienne


Mike Lawrence a écrit :

David Kahle

unread,
Feb 4, 2009, 3:54:13 PM2/4/09
to Etienne Bellemare Racine, ggplot2
Here's an example of adding text, does this help?

text <- data.frame(x = 20, y = 25, label = 'test')
ggplot(aes(x = dist, y = speed), data = cars) +
  geom_point() +
  geom_text(aes(x = x, y = y, label = label), data = text)

Cheers
david.

Etienne Bellemare Racine

unread,
Feb 4, 2009, 10:51:40 PM2/4/09
to David Kahle, ggplot2
Yes,  thank you very much.

Etienne

David Kahle a écrit :
Reply all
Reply to author
Forward
0 new messages