Saving a plot from R and then copying it to a Word text file -



Saving a plot from R and then copying it to a Word text file -

this question has reply here:

how save plot image on disk? 9 answers

what have tried far:

par( mfrow = c( 1, 2 ) ) matplot(rou,type="l", ylim=range(rou)) matplot(rem,type="l", ylim=range(rem))

here sample code taken the r statistics website

basically have

create new word file create headers , sub-headers move new pages in document write text insert tables (that “data.frame” , “matrix”objects) insert plots save , close word document

code:

# install.packages("r2wd") # library(help=r2wd) require(r2wd) wdget(t) # if no word file open, start new 1 - can set if have file visiable or not wdnewdoc("c:\\this.doc") # creates new file "this.doc" name wdapplytemplate("c:\\this.dot") # applies template wdtitle("examples of r2wd (a bundle write word documents r)") # adds title file wdsection("example 1 - adding text", newpage = t) # can create header wdheading(level = 2, "header 2") wdbody("this first illustration show") wdbody("(notice how, using 2 different lines in wdbody, got 2 different paragraphs)") wdbody("(notice how can utilize this: '\ n' (without space), \n go next line)") wdbody("האם זה עובד בעברית ?") wdbody("it doesn't work hebrew...") wdbody("o.k, let's move next page (and next example)") wdsection("example 2 - adding tables", newpage = t) wdbody("table using 'format'") wdtable(format(head(mtcars))) wdbody("table without using 'format'") wdtable(head(mtcars)) wdsection("example 3 - adding lm summary", newpage = t) ## illustration ?lm ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) grouping <- gl(2,10,20, labels=c("ctl","trt")) weight <- c(ctl, trt) # wouldn't work! # temp <- summary(lm(weight ~ group)) # wdbody(temp) # here solution how implent summary.lm output word wdbody.anything <- function(output) { # function takes output of object , prints line line word document # notice in many cases need alter text font courier new roman... <- capture.output(output) for(i in seq_along(a)) { wdbody(format(a[i])) } } temp <- summary(lm(weight ~ group)) wdbody.anything(temp) wdsection("example 4 - inserting plots", newpage = t) wdplot(rnorm(100), plotfun = plot, height = 10, width =20, pointsize = 20) wdplot(rnorm(100), plotfun = plot, height = 10, width =20, pointsize = 20) wdplot(rnorm(100), plotfun = plot, height = 10, width =20, pointsize = 50) # wdpagebreak() wdsave("c:\\this.doc") # save current file (can file name use) wdquit() # close word file

r plot

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -