ggplot2 plot fill page in landscape (pdf)

I'm trying to render a plot to a PDF using the following approach:

pdf('~/Desktop/test.pdf', bg = "white", paper="USr")    
p <- ggplot(df, aes(something)) + geom_bar();
print(p)
# I'm actually printing a bunch of graphs to the PDF
dev.off()

The "USr" in the PDF function is setting up the PDF to print in landscape mode. The plot is produced and is centered on the page but there is a large right/left margin and the plot isn't scaling out to take up the full 11" available to it.

I've tried some tweaks to the pdf(...) command and to the ggplot itself. Is there a solution this way or do I need to use a dedicated reporting/pdf package like sweave or knitr?

Answers


See this discussion; bottom-line is you probably want to use paper=special and set width and height explicitly.

Edit:

Here's a lazy trick to use ggsave with multiple pages,

library(ggplot2)
plots = replicate(8, qplot(1,1), simplify=FALSE)
library(gridExtra)
p <- do.call(marrangeGrob, c(plots,ncol=1,nrow=1))

ggsave("multipage.pdf", p, width=11, height=8.5)

(but otherwise, pdf(...) followed by a for loop is just fine and sometimes clearer)


Need Your Help

Objective C: How to highlight the first cell in table view when view loads?

iphone objective-c ios uitableview highlight

I am trying to default the top cell in my table view to be highlighted whenever the subview appears.

How can I show this 2 div side by side?

html css css3 xhtml

Into a page I have the following

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.