PDF File

10 views
Skip to first unread message

Luciano Rodriguez

unread,
Jul 15, 2010, 8:00:46 PM7/15/10
to ggp...@googlegroups.com
GGPLOT2,

I am relatively new to ggplot2, but I was recently helped with developing the code below.  I was wondering, if there is a way one can save the output graph as a pdf file. 

Thanks,

Luciano

BiasF <- rbind(
   data.frame(s = qF, F = sumBias[,1], fun = 'Bias of F unweighted'),
   data.frame(s = qF, F = sumBias[,3], fun = 'Bias of F weighted'),
   data.frame(s = qF, F = sumBias[,5], fun = 'Bias of F unweighted KM'),
   data.frame(s = qF, F = sumBias[,7], fun = 'Bias of F weighted KM')
   )

ggplot(BiasF, aes(s, F, colour = fun, shape = fun)) +
   geom_point() + ylab('Bias') + xlab('Quantiles') +
   opts(labels = c(colour = 'Bias', shape = 'Bias'),
   title= 'Bias of Exponential for F')
key <- simpleKey(c(paste('n = ', n), paste('m = ', m), paste('N = ', N),
   paste('Frate = ', Frate), paste('Grate = ', Grate), paste('Rate1 = ', RATE1),
   paste('Rate2 = ', RATE2), paste('CenRate1 % = ', Rate1Per),
   paste('CenRate2 % = ', Rate2Per)), points = FALSE)
seekViewport("legend_box")
pushViewport(viewport(just=c(.525, .725)))
draw.key(key, draw=TRUE)

--
Luciano Rodriguez
Undergraduate Student
Chapman University
Mathematics and Computer Science
rodr...@mail.chapman.edu

"Go confidently in the direction of your dreams. Live the life you have imagined" -Henry David Thoreau

Erik Iverson

unread,
Jul 15, 2010, 8:12:31 PM7/15/10
to Luciano Rodriguez, ggp...@googlegroups.com
> I am relatively new to ggplot2, but I was recently helped with developing the
> code below. I was wondering, if there is a way one can save the output graph
> as a pdf file.

You might follow the advice in your signature, i.e., "Go confidently in the
direction of your dreams.", and try ?pdf. :)

There is also ?ggsave.


David Kahle

unread,
Jul 15, 2010, 8:24:20 PM7/15/10
to Luciano Rodriguez, ggp...@googlegroups.com, david...@gmail.com
Hi Luciano -

You should be able to use the pdf() command and then dev.off() at the end, as follows :

BiasF <- rbind(
   data.frame(s = qF, F = sumBias[,1], fun = 'Bias of F unweighted'),
   data.frame(s = qF, F = sumBias[,3], fun = 'Bias of F weighted'),
   data.frame(s = qF, F = sumBias[,5], fun = 'Bias of F unweighted KM'),
   data.frame(s = qF, F = sumBias[,7], fun = 'Bias of F weighted KM')
   )

pdf(file = 'mypicture.pdf')

ggplot(BiasF, aes(s, F, colour = fun, shape = fun)) + 
   geom_point() + ylab('Bias') + xlab('Quantiles') + 
   opts(labels = c(colour = 'Bias', shape = 'Bias'), 
   title= 'Bias of Exponential for F')
key <- simpleKey(c(paste('n = ', n), paste('m = ', m), paste('N = ', N), 
   paste('Frate = ', Frate), paste('Grate = ', Grate), paste('Rate1 = ', RATE1),
   paste('Rate2 = ', RATE2), paste('CenRate1 % = ', Rate1Per),
   paste('CenRate2 % = ', Rate2Per)), points = FALSE)
seekViewport("legend_box")
pushViewport(viewport(just=c(.525, .725)))
draw.key(key, draw=TRUE)

dev.off()


However, have you considered something like the following?

df <- data.frame(
  x = 1:10,
  class = rep(letters[1:2], each = 5)
)

qplot(x, x, data = df, colour = class) + 
  scale_colour_discrete(
    breaks = c('a','b'),
    labels = c('\nA\nn=50\n','\nB\nn=100\n')
  )

  

It may do what you want, and even though it's a rig it's a lot easier.

Hope it helps
david.

Harlan Harris

unread,
Jul 16, 2010, 10:54:53 AM7/16/10
to ggplot2
In my view, ggsave() is much easier to use:
myplot <- ggplot(...
ggsave('myplot.pdf", myplot)

Plus, that works even if you don't want to ever display myplot on the
screen.

Also, I don't think it's a good idea to suggest a beginner to ggplot
ever use qplot(). It leads to misunderstandings about what ggplot is
and does, and what ggplot objects are and how they're constructed. All
the syntactic sugar that's available is very misleading and prevents
the intuitions that make the grammar of graphics so powerful.

-Harlan
Reply all
Reply to author
Forward
0 new messages