Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing the quality of EMF outputs in R and ggplot2

Tags:

r

ggplot2

.emf

I am generating and saving an EMF file with ggplot2 and with the win.graph command. the output graph is low quality and lines looked jagged. I really need to have it in EMF format (exporting to pdf solves the problem but I need the EMF file). How can I make it high quality? (the emf output is here in case you like to see it)

require(ggplot2)
my.dates = as.Date(c("2011-07-22","2011-07-23",
                     "2011-07-24","2011-07-28","2011-07-29"))
my.vals  = c(5,6,8,7,3)
my.data <- data.frame(date =my.dates, vals = my.vals)
plot(my.dates, my.vals)
p <- ggplot(data = my.data, aes(date,vals))+ geom_line(size = 1.5)
p <- p + scale_x_date(format="%m/%d", ' ')
win.graph(width=860/72, height=450/72,pointsize = 12)

print(p)
savePlot("c:/test.emf",type="emf")
dev.off()
like image 506
Mark Avatar asked Jul 10 '11 04:07

Mark


1 Answers

EMF is vector based. I was pasting the EMF files into powerpoint slides and I noticed that they are rendered as low res. If you right click on the EMF file and select edit photo it will render it properly. That solved my problem.

Update: I went ahead and wrote a little VBA script that ungroups the EMF file. It breaks it into a graph object that can be easily scaled. It looks very nice now.

like image 125
Mark Avatar answered Nov 07 '22 08:11

Mark