[R] Fw: Save multiple plots as pdf or jpeg
Uwe Ligges
ligges at statistik.tu-dortmund.de
Thu Apr 17 00:55:06 CEST 2014
On 16.04.2014 11:00, Pavneet Arora wrote:
> Hello Uwe
>
> Can you explain what you mean by "try to plot the sensity only with few
> hundreds of segemnts"
>
> Do you mean that I should take some kind of sample and do it? And if so
> what's the best number for the sample and how do i ensure that its not
> biased?
Just ensure that you various plots do not contain too many elements to
be plotted. If you really need many of these, a bitmap graphics may be
exceptionally a better idea.
Best,
Uwe Ligges
>
>
>
>
>
> From: Uwe Ligges <ligges at statistik.tu-dortmund.de>
> To: Pavneet Arora/UK/RoyalSun at RoyalSun, r-help at r-project.org,
> pavneet17 at yahoo.co.uk
> Date: 15/04/2014 14:08
> Subject: Re: [R] Fw: Save multiple plots as pdf or jpeg
>
>
>
> You have > 1e6 observations and your lines() have these many segments,
> try to plot the sensity only with few hndreds of segemnts.
>
> Best,
> Uwe Ligges
>
>
> On 15.04.2014 12:27, Pavneet Arora wrote:
>> Hello All,
>>
>> I have multiple plots that I want to save it a single file. At the
> moment,
>> I am saving as pdf. Each plot has a qqnorm, qqline, tiny histogram in
> the
>> top left graph with its density drawn top of it and the normal
>> superimposed on the histogram.
>>
>> As a result, the pdf takes forever to load and doesn?t let me print, as
> it
>> runs out of memory. I was wondering if there is a way if I can save each
>> plot as jpeg and then export it on pdf. Will that make it quicker in
>> loading? If so, how can I do this? And if not, then what are the
>> alternatives.
>>
>> The code that I have at the moment is as follows:
>>
>>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> pdf(file="C:/qqnorm/qqnorms.pdf") ##- Saves all plots in the same pdf
> file
>>
>>
>> for (k in 1:ncol(nums2)){
>> par(mfrow=c(1,1))
>>
>> ##- QQNorm
>> qqnorm(nums2[,k],col="lightblue",main=names(nums2)[k])
>> qqline(nums2[,k],col="red",lwd=2)
>>
>> ##- Tiny Histogram
>> op = par(fig=c(.02,.5,0.4,0.98), new=TRUE)
>> hist(nums2[,k],freq=F,col="blue",xlab="", ylab="", main="",
>> axes=F,density=20)
>>
>> ##- Density of the variable
>> lines(density(nums2[,k],na.rm=T), col="darkred", lwd=2)
>>
>> ##- Super-imposed Normal Density
>> curve(dnorm(x,mean=mean(nums2[,k],na.rm=T),sd=sd(nums2[,k],na.rm=T)),
>> col="black",lwd=3,add=T) ##- Footnote: title1 <- "nums2[k]"
>>
>> library(moments)
>> s_kurt <- kurtosis (nums2[,k])
>> s_skew <- skewness (nums2[,k])
>> mtxt <- paste ("Variable=",title1, ":" ,
>> "Kurt=",round(s_kurt,digits=4), "Skew",
>> round(s_skw,digits=4), sep=" ")
>>
>> mtext (mtxt,col="green4",side=1,line=15.6,adj=0.0,cex=0.8,font=2,las=1)
>>
>> }
>> dev.off()
>>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> Structure of My data:
>>
>> str(nums2)
>> 'data.frame': 1355615 obs. of 39 variables:
>> $ month : int 1 1 1 1 1 1 1 1 1 1 ...
>> $ Location_Easting_OSGR : int 525680 524170 524520 526900
>> 528060 524770 524220 525890 527350 524550 ...
>> $ Location_Northing_OSGR : int 178240 181650 182240 177530
>> 179040 181160 180830 179710 177650 180810 ...
>> $ Longitude : num -0.191 -0.212 -0.206 -0.174
>> -0.157 ...
>> $ Latitude : num 51.5 51.5 51.5 51.5 51.5 ...
>> $ Police_Force : int 1 1 1 1 1 1 1 1 1 1 ...
>> $ Number_of_Vehicles : int 1 1 2 1 1 2 2 1 2 2 ...
>> $ Number_of_Casualties : int 1 1 1 1 1 1 1 2 2 5 ...
>> $ Day_of_Week : int 3 4 5 6 2 3 5 6 7 7 ...
>> $ Local_Authority__District_ : int 12 12 12 12 12 12 12 12 12 12
>> ...
>> $ X_1_st_Road_Class : int 3 4 5 3 6 6 5 3 3 4 ...
>> $ X_1_st_Road_Number : int 3218 450 0 3220 0 0 0 315
> 3212
>> 450 ...
>> $ Road_Type : int 6 3 6 6 6 6 6 3 6 6 ...
>> $ Speed_limit : int 30 30 30 30 30 30 30 30 30 30
>> ...
>> $ Junction_Detail : int 0 6 0 0 0 0 3 0 6 3 ...
>> $ Junction_Control : int -1 2 -1 -1 -1 -1 4 -1 2 4 ...
>> $ X_2_nd_Road_Class : int -1 5 -1 -1 -1 -1 6 -1 4 5 ...
>> $ X_2_nd_Road_Number : int 0 0 0 0 0 0 0 0 304 0 ...
>> $ Pedestrian_Crossing_Human_Contro: int 0 0 0 0 0 0 0 0 0 0 ...
>> $ Pedestrian_Crossing_Physical_Fac: int 1 5 0 0 0 0 0 0 5 8 ...
>> $ Light_Conditions : int 1 4 4 1 7 1 4 1 4 1 ...
>> $ Weather_Conditions : int 2 1 1 1 1 2 1 1 1 1 ...
>> $ Road_Surface_Conditions : int 2 1 1 1 2 2 1 1 1 1 ...
>> $ Special_Conditions_at_Site : int 0 0 0 0 0 6 0 0 0 0 ...
>> $ Carriageway_Hazards : int 0 0 0 0 0 0 0 0 0 0 ...
>> $ Urban_or_Rural_Area : int 1 1 1 1 1 1 1 1 1 1 ...
>> $ Did_Police_Officer_Attend_Scene_: int 1 1 1 1 1 1 1 1 1 1 ...
>> $ year : int 2005 2005 2005 2005 2005 2005
>> 2005 2005 2005 2005 ...
>> $ m : int 1 1 1 1 1 1 1 1 1 1 ...
>> $ Qrtr : int 1 1 1 1 1 1 1 1 1 1 ...
>> $ h2 : int 17 17 0 10 21 12 20 17 22 16
> ...
>> $ NumberVehGrp : int 1 1 2 1 1 2 2 1 2 2 ...
>> $ NumberCasultGrp : int 1 1 1 1 1 1 1 2 2 5 ...
>> $ lati_round : num 51.5 51.5 51.5 51.5 51.5 ...
>> $ longi_round : num -0.19 -0.21 -0.21 -0.17 -0.16
>> -0.2 -0.21 -0.19 -0.17 -0.21 ...
>> $ lati_2dp : num 51.5 51.5 51.5 51.5 51.5 ...
>> $ lati_1dp : num 51.5 51.5 51.5 51.5 51.5 51.5
>> 51.5 51.5 51.5 51.5 ...
>> $ longi_2dp : num -0.19 -0.21 -0.21 -0.17 -0.16
>> -0.2 -0.21 -0.19 -0.17 -0.21 ...
>> $ longi_1dp : num -0.2 -0.2 -0.2 -0.2 -0.2 -0.2
>> -0.2 -0.2 -0.2 -0.2 ...
>>
>>
>> Also when saving as jpeg in R, I realise there is a wildcard in
> filenames,
>> i.e.. 6 plots can be saved as:
>> jpeg(filename="foo%03d.jpeg",. . . )
>> dev.off()
>>
>> But is there any way, where I can save them as the variable name instead
> -
>> so perhaps some use of macro or loop to do so?
>>
>>
>>
>>
> ***********************************************************************************************************************************************************************************************************************
>> MORE TH>N is a trading style of Royal & Sun Alliance Insurance plc (No.
> 93792). Registered in England and Wales at St. Markâ??s Court, Chart Way,
> Horsham, West Sussex, RH12 1XL.
>>
>> Authorised by the Prudential Regulation Authority and regulated by the
> Financial Conduct Authority and the Prudential Regulation Authority.
>>
> ************************************************************************************************************************************************************************************************************************
>>
>> [[alternative HTML version deleted]]
>>
>>
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
> ______________________________________________________________________________________________
> The following message has been automatically added to comply with the RSA
> Group IT Security requirements:
>
> This email have arrived via the Internet without any form of encryption or
> verification of the sender.
> As such you should be especially cautious about its origin and content.
> Replies which contain sensitive information or legal/contractual
> obligations are particularly vulnerable.
> In these cases you should not reply unless you are authorised to do so,
> and adequate encryption is employed.
>
> If you have any questions, please speak to the Service Centre on x7979.
> ______________________________________________________________________________________________
>
>
>
> ***********************************************************************************************************************************************************************************************************************
> MORE TH>N is a trading style of Royal & Sun Alliance Insurance plc (No. 93792). Registered in England and Wales at St. Mark’s Court, Chart Way, Horsham, West Sussex, RH12 1XL.
>
> Authorised by the Prudential Regulation Authority and regulated by the Financial Conduct Authority and the Prudential Regulation Authority.
> ************************************************************************************************************************************************************************************************************************
>
More information about the R-help
mailing list