[R] A panel of contour plots through a iteration process

Jose Iparraguirre Jose.Iparraguirre at ageuk.org.uk
Thu Nov 8 16:51:57 CET 2012


Hi Loukia,

I think the problem stems from the fact that the filled.contour "uses the layout function and so is restricted to a full page display" as its documentation reads. And if you look at the documentation of the layout function, it says that it is "totally incompatible with the other mechanisms for arranging plots on a device: par(mfrow), par(mfcol)".

However, you can use the ggplot2 package along with the function multiplot, which you can find here: http://wiki.stdout.org/rcookbook/Graphs/Multiple%20graphs%20on%20one%20page%20(ggplot2)/

It works fine with contour plots. 

You need to create your 11 contour plots first. 
For example, to keep things simple, let's create 11 equal contour plots:

> library(reshape2)
> volcano3d = melt(volcano)
> names(volcano3d) = c("x", "y", "z")
> library(ggplot2)

> p1 = ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p2 = ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p3= ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p4 = ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p5 = ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p6 = ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p7 = ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p8 = ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p9 = ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p10 = ggplot(volcano3d, aes(x, y, z = z))+
+  stat_contour(aes(colour = ..level..))
> p11 = ggplot(volcano3d, aes(x, y, z = z))+
>  stat_contour(aes(colour = ..level..))

and then run the multiplot function:

> multiplot(p1, p2, p3, p4, p5,p6,p7,p8,p9,p10,p11, cols=2) # the plots will be displayed along two columns.

With so many plots in one page, you'll need to work on the individual margins of each plot and the size of the legends, etc, though!

Hope this helps,

José

José Iparraguirre
Chief Economist
Age UK

T 020 303 31482
E Jose.Iparraguirre at ageuk.org.uk
Twitter @jose.iparraguirre at ageuk


Tavis House, 1- 6 Tavistock Square
London, WC1H 9NB
www.ageuk.org.uk | ageukblog.org.uk | @ageukcampaigns 


For a copy of our new Economic Monitor and the full Chief Economist's report, visit the Age UK Knowledge Hub http://www.ageuk.org.uk/professional-resources-home/knowledge-hub-evidence-statistics/


For evidence and statistics on the older population, visit the Age UK Knowledge Hub http://www.ageuk.org.uk/professional-resources-home/knowledge-hub-evidence-statistics/



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Loukia Spineli
Sent: 08 November 2012 13:11
To: r-help at r-project.org help
Subject: [R] A panel of contour plots through a iteration process

Dear all,

as you can see from the code I want to create *a panel of 11 contour
plots through
a iteration process*. I found a thread that address the issue of plotting
many contour.plots in the same device, but it does not address my problem!
I emphasize that the 11 contour plots must be appeared in the same device
through an iteration process and NOT individually!

par(mfrow=c(4,3)) # I want them to appear like a 4*3 matrix
for(i in 1:11){
p[i]]<-matrix(p[[i]],nrow=l10ncol=length10,byrow=T)
filled.contour(p[i]], etc,etc...)
}
par(mfrow=c(1,1))

Any suggestions would be really appreciated! Thank you very much in
advance!!

All the best,
Loukia

	[[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.

Wrap Up & Run 10k next March to raise vital funds for Age UK

Six exciting new 10k races are taking place throughout the country and we want you to join in the fun! Whether you're a runner or not, these are
events are for everyone ~ from walking groups to serious athletes. The Age UK Events Team will provide you with a training plan to suit your 
level and lots of tips to make this your first successful challenge of 2012. Beat the January blues and raise some vital funds to help us 
prevent avoidable deaths amongst older people this winter.


Sign up now! www.ageuk.org.uk/10k

Coming to; London Crystal Palace, Southport, Tatton Park, Cheshire Harewood House, Leeds,Coventry, Exeter


Age UK Improving later life
www.ageuk.org.uk


 

-------------------------------
Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). 
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer 
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health 
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and 
regulated by the Financial Services Authority. 
------------------------------

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are 
addressed. If you receive a message in error, please advise the sender and delete immediately.

Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not 
necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing 
through its network and may block or modify mails which are deemed to be unsuitable.

Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged 
on 1st April 2009.  Together they have formed the Age UK Group, dedicated to improving the lives of people in later life.  The three national 
Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: 
Age Scotland, Age NI, Age Cymru.













More information about the R-help mailing list