adding a title to a pdf

34 views
Skip to first unread message

Ori Davidov

unread,
Jan 27, 2012, 1:12:22 PM1/27/12
to ggp...@googlegroups.com

I have recently been acquainted ggplot2, which I like very much.

 

I am producing a plot intended for submission. It’s a 2 by 2 grid of plots written to a pdf file.  To that end I am using the code as explained on page 154 of the ggplot2 book, i.e.,

 

# this is just test data:

 

x = 1:20

y = 1 + 2*x+rnorm(20)

mydata = as.data.frame(cbind(x,y))

 

(a = qplot(x,y,data=mydata, main = "Figure 1(a)", xlab = "Delta", ylab = "Relative MSE") )

(b = qplot(x,y,data=mydata, main = "Figure 1(b)", xlab = "Delta", ylab = "Relative MSE") )

(c = qplot(x,y,data=mydata,main = "Figure 1(c)", xlab = "Delta", ylab = "Relative MSE") )

(d =qplot(x,y,data=mydata,main = "Figure 1(d)", xlab = "Delta", ylab = "Relative MSE") )

 

pdf("Figure1.pdf", width = 8, height =8, title = This is Figure 1")

grid.newpage()

pushViewport(viewport(layout = grid.layout(2,2)))

vplayout = function(x,y)

viewport(layout.pos.row = x, layout.pos.col = y)

print(a,vp = vplayout(1,1))

print(b,vp = vplayout(1,2))

print(c,vp = vplayout(2,1))

print(d,vp = vplayout(2,2))

dev.off()

 

I would like also to add a main title to the page. How is that done? 

 

Thanks for your help,

 

Ori

 

Ori Davidov

Department of Statistics

Univesity of Haifa

 

Hadley Wickham

unread,
Feb 10, 2012, 8:03:30 AM2/10/12
to dav...@stat.haifa.ac.il, ggp...@googlegroups.com
You'll need to use grid.text to place a text element in the
appropriate place. I never remember how to do this off the top of my
head, but hopefully someone else can help.

Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

baptiste auguie

unread,
Feb 10, 2012, 3:45:55 PM2/10/12
to dav...@stat.haifa.ac.il, ggp...@googlegroups.com
Hi,

Try this,

library(gridExtra)

## default:
## combined <- grid.arrange(a, b, c, d, main = "This is Figure 1")

large_title <- textGrob("This is Figure 1", gp=gpar(fontsize=18, col="red"))
combined <- arrangeGrob(a, b, c, d, main = large_title)
ggsave(combined, file="Figure1.pdf", width = 8, height =8)

HTH,

baptiste

Reply all
Reply to author
Forward
0 new messages