[R] How to overlay contourplot of a dataset A and a levelplot of a dataset B?
Pascal Oettli
kridox at ymail.com
Mon Aug 4 04:32:50 CEST 2014
Hi Charles,
You don't need "as.layer".
levelplot(z ~ x*y,grid2) + contourplot(z ~ x*y,grid1)
is enough.
Regards,
Pascal
On Sun, Aug 3, 2014 at 5:59 PM, Charles Novaes de Santana
<charles.santana at gmail.com> wrote:
> Dear all,
>
> Just to inform that I have solved my problem in a very elegant way, thanks
> to the layer approach given by package latticeExtra.
>
> After loading my grids like before:
>
> x<-1:10
> y<-1:10
> grid1<-expand.grid(x=x,y=y)
> grid2<-expand.grid(x=x,y=y)
> z1<-grid1$x^2 + grid1$y^2
> z2<-2*grid2$x^2 - grid2$y^2
> grid1$z<-z1
> grid2$z<-z2
>
> I just need to do:
>
> levelplot(z ~ x*y,grid2) + as.layer(contourplot(z ~ x*y,grid1));
>
> The result is a beautiful plot with a contourplot over a levelplot. There
> are some examples of overlay of trellis plots in the manual of
> latticeExtra: http://latticeextra.r-forge.r-project.org/
>
> Thank you for your attention,
>
> Best,
>
> Charles
>
>
> On Sat, Aug 2, 2014 at 4:01 PM, Charles Novaes de Santana <
> charles.santana at gmail.com> wrote:
>
>> Dear all,
>>
>> Does anyone know a way to overlay a contourplot and a levelplot of
>> different datasets, both datasets with the same dimension?
>>
>> Let's say I have 2 10x10 grids, like those below:
>>
>> library(lattice)
>>
>> x<-1:10
>> y<-1:10
>> grid1<-expand.grid(x=x,y=y)
>> grid2<-expand.grid(x=x,y=y)
>> z1<-grid1$x^2 + grid1$y^2
>> z2<-2*grid2$x^2 - grid2$y^2
>> grid1$z<-z1
>> grid2$z<-z2
>>
>> I would like to plot z1 and z2 in the same plot: z1 as a contourline and
>> z2 as a levelplot. I tried to do this in two ways, without success:
>>
>> plot.new();
>> contourplot(z ~ x*y,grid1)
>> par(new=T)
>> levelplot(z ~ x*y,grid2)
>>
>> and
>>
>> levelplot(z ~ x*y,grid1,region=FALSE,contour=TRUE)
>> par(new=T)
>> levelplot(z ~ x*y,grid2,region=TRUE,contour=FALSE)
>>
>> Any clue?
>>
>> Thank you very much for your time and any help!
>>
>> Charles
>>
>> --
>> Um axé! :)
>>
>> --
>> Charles Novaes de Santana, PhD
>> http://www.imedea.uib-csic.es/~charles
>>
>
>
>
> --
> Um axé! :)
>
> --
> Charles Novaes de Santana, PhD
> http://www.imedea.uib-csic.es/~charles
>
> [[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.
>
--
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan
More information about the R-help
mailing list