Thanks again.
# Loop code that does not work.
VADeaths_flat_df = stack(as.data.frame(VADeaths))
names(VADeaths_flat_df) = c('Data','Person')
for(ii in 1:5)
{
VADeaths_title<-paste("C:/Images/VADeaths", ii,"_%02d.wmf", sep = "")
# Produce a Windows Meta File Format Plot
win.metafile(file=as.character(VADeaths_title), pointsize = 10)
counts <- ddply(VADeaths_flat_df, .(cut(Data, breaks=fullseq(range(Data), 20)), Person), nrow)
names(counts) <- c("bin", "person", "n")
qplot(person, n, data = counts, fill = person, geom="bar", stat="identity", width = 0.9) +
facet_grid(. ~ bin) + opts(axis.text.x = NULL) + opts(axis.text.y = theme_text(colour = "red")) +
opts(strip.text.x = theme_text(colour = "green", size=14))
dev.off()
}
| From: | Jason Rupert <jasonk...@yahoo.com> |
| To: | ggp...@googlegroups.com |
| Date: | 03/26/2009 09:40 AM |
| Subject: | Printing ggplot2 to WMF |
******************************************************************* IMPORTANT MESSAGE FOR RECIPIENTS IN THE U.S.A.: This message may constitute an advertisement of a BD group's products or services or a solicitation of interest in them. If this is such a message and you would like to opt out of receiving future advertisements or solicitations from this BD group, please forward this e-mail to optout...@bd.com. ******************************************************************* This message (which includes any attachments) is intended only for the designated recipient(s). It may contain confidential or proprietary information and may be subject to the attorney-client privilege or other confidentiality protections. If you are not a designated recipient, you may not review, use, copy or distribute this message. If you received this in error, please notify the sender by reply e-mail and delete this message. Thank you. ******************************************************************* Corporate Headquarters Mailing Address: BD (Becton, Dickinson and Company) 1 Becton Drive Franklin Lakes, NJ 07417 U.S.A. *******************************************************************
In order to keep the scales on plots for multiple data sets it appears that I need to add an empty bin in the bar plot.
I tried to do this in the example below by expanding the range, i.e. range(c(Data, max_range)) where max_range is the desired max x-scale, however apparently this had no effect. I hoped it would have added an "empty" bin from 80-100.
Thanks for your help.
VADeaths_flat_df = stack(as.data.frame(VADeaths))
names(VADeaths_flat_df) = c('Data','Person')
max_range<-100
counts <- ddply(VADeaths_flat_df, .(cut(Data, breaks=fullseq(range(c(Data, max_range)), 20)), Person), nrow)
names(counts) <- c("bin", "person", "n")
print(qplot(person, n, data = counts, fill = person, geom="bar", stat="identity", width = 0.9) + facet_grid(. ~ bin) + opts(axis.text.x = NULL) + opts(axis.text.y = theme_text(colour = "red")) + opts(strip.text.x = theme_text(colour = "green", size=14)))