Quantcast

Smoothing a persp graph

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Smoothing a persp graph

Guillaume Chapron
Hi,

I'm unable to find a way to smooth data for a persp() graph.

Example, suppose that I have data x,y,z like this:

x <- 1:10
y <- 1:10

k <- 20
z <- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
persp(x, y, z, theta = 35, phi = 25)

The graph is not very nice. Is there a way to smooth the z data so that at the end the graph would look more like something like that:

k <- 2
z <- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
persp(x, y, z, theta = 35, phi = 25)

There seems to be many smoothing functions in R (e.g. loess) but I have not been able to find one for a 3D graph.

Thanks!

Guillaume

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Smoothing a persp graph

Dániel Kehl
Take a look at the

kde2d
function in the MASS package, maybe it helps.

Best
kd



2012.06.19. 14:26 keltezéssel, Guillaume Chapron írta:

> Hi,
>
> I'm unable to find a way to smooth data for a persp() graph.
>
> Example, suppose that I have data x,y,z like this:
>
> x<- 1:10
> y<- 1:10
>
> k<- 20
> z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
> persp(x, y, z, theta = 35, phi = 25)
>
> The graph is not very nice. Is there a way to smooth the z data so that at the end the graph would look more like something like that:
>
> k<- 2
> z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
> persp(x, y, z, theta = 35, phi = 25)
>
> There seems to be many smoothing functions in R (e.g. loess) but I have not been able to find one for a 3D graph.
>
> Thanks!
>
> Guillaume
>
> ______________________________________________
> [hidden email] 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.
>
>
>

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Smoothing a persp graph

David Carlson
kde2d is for two dimensional data. The persp graph is 3d.
 
Look at the StatDA package, particularly the Vignette for that package,
"Tutorial to the package StatDA" which discusses smoothing techniques
and kriging:

http://cran.r-project.org/web/packages/StatDA/vignettes/StatDA.pdf

For more options look at the Spatial Task View:

http://cran.r-project.org/web/views/Spatial.html

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Kehl Dániel
> Sent: Tuesday, June 19, 2012 8:42 AM
> To: [hidden email]
> Subject: Re: [R] Smoothing a persp graph
>
> Take a look at the
>
> kde2d
> function in the MASS package, maybe it helps.
>
> Best
> kd
>
>
>
> 2012.06.19. 14:26 keltezissel, Guillaume Chapron mrta:
> > Hi,
> >
> > I'm unable to find a way to smooth data for a persp() graph.
> >
> > Example, suppose that I have data x,y,z like this:
> >
> > x<- 1:10
> > y<- 1:10
> >
> > k<- 20
> > z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
> > persp(x, y, z, theta = 35, phi = 25)
> >
> > The graph is not very nice. Is there a way to smooth the z data so
> that at the end the graph would look more like something like that:
> >
> > k<- 2
> > z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
> > persp(x, y, z, theta = 35, phi = 25)
> >
> > There seems to be many smoothing functions in R (e.g. loess) but I
> have not been able to find one for a 3D graph.
> >
> > Thanks!
> >
> > Guillaume
> >
> > ______________________________________________
> > [hidden email] 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.
> >
> >
> >
>
>
> [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Smoothing a persp graph

David Winsemius

On Jun 19, 2012, at 10:02 AM, David L Carlson wrote:

> kde2d is for two dimensional data. The persp graph is 3d.

Huh? The question asked about plotting data that was 2d. The third  
dimension was to be the density. kde2d in package MASS or the  
similarly named function in package KernSmooth would seem to be on  
point here.

--
David.


>
> Look at the StatDA package, particularly the Vignette for that  
> package,
> "Tutorial to the package StatDA" which discusses smoothing techniques
> and kriging:
>
> http://cran.r-project.org/web/packages/StatDA/vignettes/StatDA.pdf
>
> For more options look at the Spatial Task View:
>
> http://cran.r-project.org/web/views/Spatial.html
>
> ----------------------------------------------
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
>> -----Original Message-----
>> From: [hidden email] [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Kehl Dániel
>> Sent: Tuesday, June 19, 2012 8:42 AM
>> To: [hidden email]
>> Subject: Re: [R] Smoothing a persp graph
>>
>> Take a look at the
>>
>> kde2d
>> function in the MASS package, maybe it helps.
>>
>> Best
>> kd
>>
>>
>>
>> 2012.06.19. 14:26 keltezissel, Guillaume Chapron mrta:
>>> Hi,
>>>
>>> I'm unable to find a way to smooth data for a persp() graph.
>>>
>>> Example, suppose that I have data x,y,z like this:
>>>
>>> x<- 1:10
>>> y<- 1:10
>>>
>>> k<- 20
>>> z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
>>> persp(x, y, z, theta = 35, phi = 25)
>>>
>>> The graph is not very nice. Is there a way to smooth the z data so
>> that at the end the graph would look more like something like that:
>>>
>>> k<- 2
>>> z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
>>> persp(x, y, z, theta = 35, phi = 25)
>>>
>>> There seems to be many smoothing functions in R (e.g. loess) but I
>> have not been able to find one for a 3D graph.
>>>
>>> Thanks!
>>>
>>> Guillaume
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>>
>>>
>>>
>>
>>
>> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Smoothing a persp graph

Guillaume Chapron
In reply to this post by Guillaume Chapron
On Jun 19, 2012, at 10:02 AM, David L Carlson wrote:

kde2d is for two dimensional data. The persp graph is 3d.

Huh? The question asked about plotting data that was 2d. The third  
dimension was to be the density. kde2d in package MASS or the  
similarly named function in package KernSmooth would seem to be on  
point here.

No, I don't think that I can use kde2d because the I already have my z data and it is this z data that I need to smooth. My question is analog to smoothing level curves on a map, the altitude is given by data, and one wants to have nice level curves that ignore small variations of the terrain.

Guillaume



        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Smoothing a persp graph

David Carlson
In reply to this post by David Winsemius
The kde2d function estimates density using the spacing of the points in two
dimensions. The requester has gridded (x, y) data with a z value. The
function call for kde2d takes x and y and compute z values that estimate
point density.

Kde2d is used for point data where you want to estimate the density of the
points in 2d. Use kde2d to produce the gridded data you need to pass on to
contour or persp, but the requester already has gridded data with a z value
that he wants to smooth (e.g. elevation, depth to an interesting deposit,
thickness of a stratum, rainfall, tree frog density), a standard problem in
geostatistics.

-------
David 2


> -----Original Message-----
> From: David Winsemius [mailto:[hidden email]]
> Sent: Tuesday, June 19, 2012 10:00 AM
> To: [hidden email]
> Cc: "'Kehl Dániel'"; [hidden email]
> Subject: Re: [R] Smoothing a persp graph
>
>
> On Jun 19, 2012, at 10:02 AM, David L Carlson wrote:
>
> > kde2d is for two dimensional data. The persp graph is 3d.
>
> Huh? The question asked about plotting data that was 2d. The third
> dimension was to be the density. kde2d in package MASS or the
> similarly named function in package KernSmooth would seem to be on
> point here.
>
> --
> David.
>
>
> >
> > Look at the StatDA package, particularly the Vignette for that
> > package,
> > "Tutorial to the package StatDA" which discusses smoothing techniques
> > and kriging:
> >
> > http://cran.r-project.org/web/packages/StatDA/vignettes/StatDA.pdf
> >
> > For more options look at the Spatial Task View:
> >
> > http://cran.r-project.org/web/views/Spatial.html
> >
> > ----------------------------------------------
> > David L Carlson
> > Associate Professor of Anthropology
> > Texas A&M University
> > College Station, TX 77843-4352
> >
> >> -----Original Message-----
> >> From: [hidden email] [mailto:r-help-bounces@r-
> >> project.org] On Behalf Of Kehl Dániel
> >> Sent: Tuesday, June 19, 2012 8:42 AM
> >> To: [hidden email]
> >> Subject: Re: [R] Smoothing a persp graph
> >>
> >> Take a look at the
> >>
> >> kde2d
> >> function in the MASS package, maybe it helps.
> >>
> >> Best
> >> kd
> >>
> >>
> >>
> >> 2012.06.19. 14:26 keltezissel, Guillaume Chapron mrta:
> >>> Hi,
> >>>
> >>> I'm unable to find a way to smooth data for a persp() graph.
> >>>
> >>> Example, suppose that I have data x,y,z like this:
> >>>
> >>> x<- 1:10
> >>> y<- 1:10
> >>>
> >>> k<- 20
> >>> z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
> >>> persp(x, y, z, theta = 35, phi = 25)
> >>>
> >>> The graph is not very nice. Is there a way to smooth the z data so
> >> that at the end the graph would look more like something like that:
> >>>
> >>> k<- 2
> >>> z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
> >>> persp(x, y, z, theta = 35, phi = 25)
> >>>
> >>> There seems to be many smoothing functions in R (e.g. loess) but I
> >> have not been able to find one for a 3D graph.
> >>>
> >>> Thanks!
> >>>
> >>> Guillaume
> >>>
> >>> ______________________________________________
> >>> [hidden email] 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.
> >>>
> >>>
> >>>
> >>
> >>
> >> [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
>
> David Winsemius, MD
> West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Smoothing a persp graph

Bert Gunter
In reply to this post by Guillaume Chapron
?loess, mgcv, kriging, ...  There must be hundreds. Have you consulted the
CRAN "spatial" task view?

-- Bert

On Tue, Jun 19, 2012 at 8:34 AM, Guillaume Chapron <
[hidden email]> wrote:

> On Jun 19, 2012, at 10:02 AM, David L Carlson wrote:
>
> kde2d is for two dimensional data. The persp graph is 3d.
>
> Huh? The question asked about plotting data that was 2d. The third
> dimension was to be the density. kde2d in package MASS or the
> similarly named function in package KernSmooth would seem to be on
> point here.
>
> No, I don't think that I can use kde2d because the I already have my z
> data and it is this z data that I need to smooth. My question is analog to
> smoothing level curves on a map, the altitude is given by data, and one
> wants to have nice level curves that ignore small variations of the terrain.
>
> Guillaume
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>



--

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Smoothing a persp graph

David Winsemius
In reply to this post by David Carlson

On Jun 19, 2012, at 11:42 AM, David L Carlson wrote:

> The kde2d function estimates density using the spacing of the points  
> in two
> dimensions. The requester has gridded (x, y) data with a z value. The
> function call for kde2d takes x and y and compute z values that  
> estimate
> point density.
>
> Kde2d is used for point data where you want to estimate the density  
> of the
> points in 2d. Use kde2d to produce the gridded data you need to pass  
> on to
> contour or persp, but the requester already has gridded data with a  
> z value
> that he wants to smooth (e.g. elevation, depth to an interesting  
> deposit,
> thickness of a stratum, rainfall, tree frog density), a standard  
> problem in
> geostatistics.
>
> -------
> David 2

Yes. I see the point now, and your cited vignette also looks very  
helpful. Thanks.

--
David, the lesser.

>
>
>> -----Original Message-----
>> From: David Winsemius [mailto:[hidden email]]
>> Sent: Tuesday, June 19, 2012 10:00 AM
>> To: [hidden email]
>> Cc: "'Kehl Dániel'"; [hidden email]
>> Subject: Re: [R] Smoothing a persp graph
>>
>>
>> On Jun 19, 2012, at 10:02 AM, David L Carlson wrote:
>>
>>> kde2d is for two dimensional data. The persp graph is 3d.
>>
>> Huh? The question asked about plotting data that was 2d. The third
>> dimension was to be the density. kde2d in package MASS or the
>> similarly named function in package KernSmooth would seem to be on
>> point here.
>>
>> --
>> David.
>>
>>
>>>
>>> Look at the StatDA package, particularly the Vignette for that
>>> package,
>>> "Tutorial to the package StatDA" which discusses smoothing  
>>> techniques
>>> and kriging:
>>>
>>> http://cran.r-project.org/web/packages/StatDA/vignettes/StatDA.pdf
>>>
>>> For more options look at the Spatial Task View:
>>>
>>> http://cran.r-project.org/web/views/Spatial.html
>>>
>>> ----------------------------------------------
>>> David L Carlson
>>> Associate Professor of Anthropology
>>> Texas A&M University
>>> College Station, TX 77843-4352
>>>
>>>> -----Original Message-----
>>>> From: [hidden email] [mailto:r-help-bounces@r-
>>>> project.org] On Behalf Of Kehl Dániel
>>>> Sent: Tuesday, June 19, 2012 8:42 AM
>>>> To: [hidden email]
>>>> Subject: Re: [R] Smoothing a persp graph
>>>>
>>>> Take a look at the
>>>>
>>>> kde2d
>>>> function in the MASS package, maybe it helps.
>>>>
>>>> Best
>>>> kd
>>>>
>>>>
>>>>
>>>> 2012.06.19. 14:26 keltezissel, Guillaume Chapron mrta:
>>>>> Hi,
>>>>>
>>>>> I'm unable to find a way to smooth data for a persp() graph.
>>>>>
>>>>> Example, suppose that I have data x,y,z like this:
>>>>>
>>>>> x<- 1:10
>>>>> y<- 1:10
>>>>>
>>>>> k<- 20
>>>>> z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
>>>>> persp(x, y, z, theta = 35, phi = 25)
>>>>>
>>>>> The graph is not very nice. Is there a way to smooth the z data so
>>>> that at the end the graph would look more like something like that:
>>>>>
>>>>> k<- 2
>>>>> z<- outer(x, y, "*") + matrix( k*runif(100, -1, 1), 10, 10)
>>>>> persp(x, y, z, theta = 35, phi = 25)
>>>>>
>>>>> There seems to be many smoothing functions in R (e.g. loess) but I
>>>> have not been able to find one for a 3D graph.
>>>>>
>>>>> Thanks!
>>>>>
>>>>> Guillaume
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] 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.
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>
>> David Winsemius, MD
>> West Hartford, CT
>

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Loading...