One approach would be to smooth the data using `gam' from package
`mgcv'.
`vis.gam' will contour the resulting smoothed fit if you select
`plot.type="contour"'. If the results look ok but you want finer
control of
what the plot looks like then `predict.gam' can be used to predict from the
fitted smooth on any regular grid suitable for supplying to `contour'
(although you have to supply the grid!).
On Wednesday 01 October 2008 13:05, Mark wrote:> Please help me to produce smoothed contour plots.
>
> I have dependent data generated at regular intervals of two independent
> variables and would like to produce smoothed contour plots - I cannot get
> interp (alima) to produce cubic interpolations of the data, only linear
> ones. I'm interested in smoothing as the data generation process is
> stochastic and produces small variations which I'd rather
'smooth' away. I
> cannot spot what is different about my data from the examples in (akima)
> which prevents this working.
>
> here is an example of my data:
> > x
>
> 0 50 100 150 200 250 300 350 400 450 500 0 50 100 150 200 250 300
> 350 400
> [21] 450 500 0 50 100 150 200 250 300 350 400 450 500 0 50 100 150
> 200 250 300
> [41] 350 400 450 500 0 50 100 150 200 250 300 350 400 450 500 0 50
> 100 150 200
> [61] 250 300 350 400 450 500 0 50 100 150 200 250 300 350 400 450 500
> 0 50 100
> [81] 150 200 250 300 350 400 450 500 0 50 100 150 200 250 300 350 400
> 450 500 0
> [101] 50 100 150 200 250 300 350 400 450 500 0 50 100 150 200 250 300
> 350 400 450
> [121] 500
>
> > y
>
> [1] 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.05 0.05 0.05
> 0.05 0.05
> [17] 0.05 0.05 0.05 0.05 0.05 0.05 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10
> 0.10 0.10
> [33] 0.10 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.15 0.20 0.20
> 0.20 0.20
> [49] 0.20 0.20 0.20 0.20 0.20 0.20 0.20 0.25 0.25 0.25 0.25 0.25 0.25 0.25
> 0.25 0.25
> [65] 0.25 0.25 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.30 0.35
> 0.35 0.35
> [81] 0.35 0.35 0.35 0.35 0.35 0.35 0.35 0.35 0.40 0.40 0.40 0.40 0.40 0.40
> 0.40 0.40
> [97] 0.40 0.40 0.40 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45
> 0.50 0.50
> [113] 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50 0.50
>
> > zz
>
> [1] 105136 98444 95021 79375 72532 64392 57819 44413 40610 26083
> 18077
> [12] 96188 87863 80205 69503 61000 50387 44306 33432 22958 17575
> 10892
> [23] 88402 75263 65109 63717 50998 39837 28576 25960 17531
> 8510 5733
> [34] 70806 59245 53970 46113 38455 30492 23836 17870 10954
> 5218 2266
> [45] 68272 58610 47854 34834 32363 24238 19236 11789 6206
> 2515 2141
> [56] 58448 47706 43001 39592 22840 18264 11564 6292 2915
> 2228 2090
> [67] 55817 47680 38460 31693 21331 13161 8050 3162 2302
> 2120 1990
> [78] 54078 43720 32828 22618 17039 8524 4846 2392 2154
> 2068 2008
> [89] 47459 39734 29525 21325 10602 6406 3525 2207 2062
> 2014 1952
> [100] 47630 34965 28452 18966 8386 5726 2351 2145 2052
> 1999 1960
> [111] 42173 34339 27449 16743 9643 2866 2208 2096 2018
> 1937 1886
>
> [[alternative HTML version deleted]]
>
> [[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.
-- > Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603 www.maths.bath.ac.uk/~sw283