Wednesday, 15 May 2013

r - pdf font and graph formatting (win.graph) -



r - pdf font and graph formatting (win.graph) -

i came upon problem in r in combination have tried solve , searched in internet, not solve yet. hope can help me.

i run r(x64) on windows 7. graphic device automatically uses arial font, , when save graphs bitmap "font" naturally remains is. however, prefer saving graphs pdf, in case font in resulting pdf exchanged helvetica when save via gui save button.

i found solution in internet, using arial afm-files , pdf("test_auto.pdf", family = "arial"), resulted in pdf using arial font---so far good.

now have to/want alter graph layout using win.graph, , problems start. here example:

arial <- type1font(family = "arial", metrics = c("c:/r_fonts/arialplain.afm", "c:/r_fonts/arialbold.afm", "c:/r_fonts/arialitalic.afm", "c:/r_fonts/arialbolditalic.afm")) pdffonts(arial = arial) setwd("c:/pdfcrop") d1<-matrix(c(1,2,3,4,6,3),3,2) d2<-matrix(c(1,2,3,5,3,1),3,2) #pdf("test_auto.pdf", family = "arial") win.graph(8.3,12,12) layout(matrix(c(1,2),1,2,byrow=true)) plot(d1,type="l",main="gobble r") plot(d2,type="l",main="gobble r") #dev.off()

now code works create graph looks want look, have save graph manually (file->save as) , helvetica font in pdf.

alternatively can alter lower part in

pdf("test_auto.pdf", family = "arial") #win.graph(8.3,12,12) layout(matrix(c(1,2),1,2,byrow=true)) plot(d1,type="l",main="gobble r") plot(d2,type="l",main="gobble r") dev.off()

and produces pdf-file uses arial, graph has other dimensions intending. when using both pdf "cannot opened because does't contain pages" (though not 0kb in size).

is there way work, or alternative win.graph can utilize between pdf() , dev.off()?

thanks help.

oh god, i'm sorry, stupid!

during overlooked, pdf-device has own size parameters.

arial <- type1font(family = "arial", metrics = c("c:/r_fonts/arialplain.afm", "c:/r_fonts/arialbold.afm", "c:/r_fonts/arialitalic.afm", "c:/r_fonts/arialbolditalic.afm")) pdffonts(arial = arial) setwd("c:/pdfcrop") d1<-matrix(c(1,2,3,4,6,3),3,2) d2<-matrix(c(1,2,3,5,3,1),3,2) pdf("test_auto.pdf", width=8.3, height=12, family = "arial") #win.graph(8.3,12,12) layout(matrix(c(1,2),1,2,byrow=true)) plot(d1,type="l",main="gobble r") plot(d2,type="l",main="gobble r") dev.off()

thank hint, dwin

r graph fonts pdf-generation

No comments:

Post a Comment