[R] Resolution issue with exporting plots from R and write tables in Latex code for producing pdf document
Duncan Murdoch
murdoch.duncan at gmail.com
Fri Jun 8 17:01:28 CEST 2012
On 08/06/2012 10:42 AM, HJ YAN wrote:
> >
> > Dear Duncan
> >
> > Many thanks again for your help!
> >
> > Now I've mended my code in the following simplified form:
> >
> >
> > pdf("filename.pdf",paper="a4",width=8,height=12,encoding="default")
> > par(mfrow=c(2,2))
> >
> > plot(1:length(SortedDataInList1[[3]][,1]),SortedDataInList1[[3]][,4],xlim=c(1,length(SortedDataInList1[[3]][,1])),ylab="Voltage
> > 1 (v)",xlab="Date/Time ind.(10 min. int.)",type="p",cex=.0001)
> > plot(...)
> > plot(...)
> > plot(...)
> > dev.off()
Sorry, but I can't guess what all the missing parts contain. If you can
post a simplified, self-contained example, I'll take a look.
Duncan Murdoch
> >
> > And I think that has included all features I need but the outputs I
> > got only appear to show part of the figures, e.g. the frame, values on
> > x-axes (e.g. 1:length(SortedDataInList1[[3]][,1])), xlab, ylab, titles,
> > subtitles are all shown. But not values on y-axes,
> > e.g. 'SortedDataInList1[[3]][,i]' for i=4,5,6... So just 4 blank frames
> > with no data in the figure!
> >
> > Have I missed to put in some important arguments in this line??
> >
> > pdf("filename.pdf",paper="a4",width=8,height=12,encoding="default")
> >
> >
> > I have tested that the 'middle part' of my code (as shown below) works
> > fine and I can get the plots as I wanted.
> > ===============
> > par(mfrow=c(2,2))
> > plot(1:length(SortedDataInList1[[3]][,1]),SortedDataInList1[[3]][,4],xlim=c(1,length(SortedDataInList1[[3]][,1])),ylab="Voltage
> > 1 (v)",xlab="Date/Time ind.(10 min. int.)",type="p",cex=.0001)
> > plot(...)
> > plot(...)
> > plot(...)
> > ================
> >
> > Many many thanks!
> >
> > HJ
> >
> >
> >
> >
> > On Fri, Jun 8, 2012 at 11:53 AM, Duncan Murdoch<murdoch.duncan at gmail.com>wrote:
> >
> >> On 12-06-08 6:46 AM, yhj204 at googlemail.com wrote:
> >>
> >>> Dear Duncan
> >>>
> >>>
> >>>
> >>> Thanks a lot for your hints.
> >>>
> >>> As you can see from my code (just one line above the command using
> >>> dev.copy) I have tried using pdf but got same problem, so I hushed it out.
> >>>
> >>
> >> That's not the right place to put the pdf() call, it should appear before
> >> any of the graphing calls. To keep the pdf resolution, you need to plot to
> >> the pdf device.
> >>
> >> Duncan Murdoch
> >>
> >>
> >>
> >>> Any ideas??
> >>>
> >>> Many thanks!
> >>>
> >>> HJ
> >>> Sent using BlackBerry® from Orange
> >>>
> >>> -----Original Message-----
> >>> From: Duncan Murdoch<murdoch.duncan at gmail.**com<murdoch.duncan at gmail.com>
> >>> >
> >>> Date: Fri, 08 Jun 2012 05:21:52
> >>> To: HJ YAN<yhj204 at googlemail.com>
> >>> Cc: r-help at r-project.org<r-help at r-**project.org<r-help at r-project.org>>
> >>> Subject: Re: [R] Resolution issue with exporting plots from R and write
> >>> tables
> >>> in Latex code for producing pdf document
> >>>
> >>> On 12-06-07 10:08 PM, HJ YAN wrote:
> >>>
> >>>> Dear R users
> >>>>
> >>>> I am trying to exporting plots from R to an external folder, or to the
> >>>> working directory, but the resolution of plots (pdf file) largely
> >>>> reduced.
> >>>> Any way I can get same quality as my original plots?? e.g. I tested the
> >>>> plotting part using one example and obtained pretty good (/readable)
> >>>> quality for each plot in the (4*4) multiple graph. But when I did the
> >>>> loop
> >>>> and tried to export those plots out using 'dev.copy', the quality was
> >>>> not
> >>>> same. I do need this loop function as there are 400 datasets so I can
> >>>> not
> >>>> handle them manually.
> >>>>
> >>>
> >>> Don't use dev.copy. Use pdf() then dev.off() to produce the plots in
> >>> the first place.
> >>>
> >>>
> >>>
> >>>> Also I am using 'xtable' to write Latex code for my summary tables of
> >>>> the
> >>>> data (again there are 400 datasets). I saved those Latex code in a list
> >>>> and
> >>>> use 'sink()' to save them outside the loop function, which works ok.
> >>>> But as
> >>>> my table is wide, so I found that the Latex code produced by xtable can
> >>>> not
> >>>> fit my purpose well, e.g. I have set size to 'tiny' but the table still
> >>>> too
> >>>> wide. Is there an alternative package more handy to do the job? Also are
> >>>> there a good way to write some hundred tables from R to Latex for
> >>>> producing
> >>>> pdf documents in an easier fashion?? i.e. Just realised that Latex does
> >>>> not
> >>>> like compiling large amount tables/figures in one go!
> >>>>
> >>>
> >>> latex has a lot of packages for handling large tables, but it may be
> >>> better to redesign your table to not be so wide. The tables package
> >>> might help with this, but it doesn't have any particular support for
> >>> wide tables.
> >>>
> >>> Duncan Murdoch
> >>>
> >>>
> >>>
> >>>
> >>>> Any advices/ideas are greatly appreciated!
> >>>>
> >>>>
> >>>> Best wishes
> >>>> HJ
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> Below is my code...
> >>>> =====================
> >>>> SumTab<-function(Data=**SortedDataInList,StartDate="**
> >>>> 30/1/12",EndDate="31/05/12",**StartTime="22:50:00",EndTime="**
> >>>> 23:00:00"){
> >>>> Start= chron(StartDate,StartTime , format=c(dates="d/m/y",
> >>>> times="h:m:s"))
> >>>> End= chron(EndDate,EndTime , format=c(dates="d/m/y", times="h:m:s"))
> >>>> deltat<- times("00:10:00")
> >>>> TT<- seq(Start,End, by = times("00:10:00"))
> >>>> TT1 = substr(TT, 2, 18)
> >>>>
> >>>>
> >>>> Data1=Data
> >>>> for (i in 1:length(Data1)){
> >>>> SumTab1[[i]]= matrix(NA, nrow=5, ncol=ncol(SortedDataInList[[i]**
> >>>> ])-4)
> >>>> SortedDataInList1[[i]]= matrix(NA, nrow=length(TT1),
> >>>> ncol=ncol(Data1[[i]]))
> >>>>
> >>>> SortedDataInList1[[i]]=Data1[[**i]][match(as.character(TT1),**
> >>>> as.character(Data1[[i]][,1])),**]
> >>>>
> >>>>
> >>>> SumTab1[[i]][1,]<-apply(**SortedDataInList1[[i]][,4:16],**2,min)
> >>>> SumTab1[[i]][2,]<-apply(**SortedDataInList1[[i]][,4:16],**2,mean)
> >>>> SumTab1[[i]][3,]<-apply(**SortedDataInList1[[i]][,4:16],**
> >>>> 2,median)
> >>>> SumTab1[[i]][4,]<-apply(**SortedDataInList1[[i]][,4:16],**2,sd)
> >>>> SumTab1[[i]][5,]<-apply(**SortedDataInList1[[i]][,4:16],**2,max)
> >>>>
> >>>>
> >>>>
> >>>> colnames(SumTab1[[i]])=c("**vOL1","VOL2","VOL3","CUR1","**
> >>>> CUR2","CUR3","THD1","THD2","**THD3","RPD","RPR","RAPD","**RAPR")
> >>>> rownames(SumTab1[[i]])=c("Min"**,"Mean","Standard
> >>>> Deviation","Median","Max")
> >>>>
> >>>>
> >>>> SumLax[[i]]<-xtable(SumTab1[[**i]],label=as.character(**
> >>>> StationsInDir[i]),caption=as.**character(StationsInDir[i]))
> >>>>
> >>>>
> >>>> par(mfrow=c(4,4),oma=c(4,0,2,**0))
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,4],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Voltage
> >>>> 1 (v)",xlab="Date/Time ind.(10 min. int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,5],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Voltage
> >>>> 2 (v)",xlab="Date/Time ind.(10 min. int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,6],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Voltage
> >>>> 3 (v)",xlab="Date/Time ind.(10 min. int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,7],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Current
> >>>> 1 (A)",xlab="Date/Time ind.(10 min. int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,8],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Current
> >>>> 2 (A)",xlab="Date/Time ind.(10 min. int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,9],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Current
> >>>> 3 (A)",xlab="Date/Time ind.(10 min. int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,10],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Total
> >>>> harmonic distortion 1 (%)",xlab="Date/Time ind.(10 min.
> >>>> int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,11],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Total
> >>>> harmonic distortion 2 (%)",xlab="Date/Time ind.(10 min.
> >>>> int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,12],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Total
> >>>> harmonic distortion 3 (%)",xlab="Date/Time ind.(10 min.
> >>>> int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,13],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Real
> >>>> power delivered (mw)",xlab="Date/Time ind.(10 min.
> >>>> int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,14],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Real
> >>>> power received (mw)",xlab="Date/Time ind.(10 min.
> >>>> int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,15],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Reactive
> >>>> power delivered (MVAr)",xlab="Date/Time ind.(10 min.
> >>>> int.)",type="p",cex=.001)
> >>>>
> >>>> plot(1:length(**SortedDataInList1[[i]][,1]),**
> >>>> SortedDataInList1[[i]][,16],**xlim=c(1,length(**
> >>>> SortedDataInList1[[i]][,1])),**ylab="Reactive
> >>>> power received (MVAr)",xlab="Date/Time ind.(10 min.
> >>>> int.)",type="p",cex=.001)
> >>>> title(main=StationsInDir[i],**outer=TRUE,cex.main=2.0)
> >>>> mtext(side=1,Start, outer = TRUE, line=0,cex = 0.6)
> >>>> mtext(side=1,End, outer = TRUE, line=2,cex = 0.6)
> >>>>
> >>>>
> >>>> #pdf(paste(as.character(**StationsInDir[i]),".pdf"))
> >>>> dev.copy(pdf,file=paste(as.**character(StationsInDir[i]),".**
> >>>> pdf"))
> >>>> dev.off()
> >>>>
> >>>> }
> >>>> }
> >>>>
> >>>> [[alternative HTML version deleted]]
> >>>>
> >>>> ______________________________**________________
> >>>> R-help at r-project.org mailing list
> >>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
> >>>> PLEASE do read the posting guide http://www.R-project.org/**
> >>>> posting-guide.html<http://www.r-project.org/posting-guide.html>
> >>>> and provide commented, minimal, self-contained, reproducible code.
> >>>>
> >>>
> >>>
> >>
> >
>
More information about the R-help
mailing list