[R] How to use contour plot?

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Tue Nov 16 11:24:04 CET 2021


On 16/11/2021 3:45 a.m., Luigi Marongiu wrote:
> Hello,
> I have a dataframe with 3 values and that I would like to plot with contour:
> ```
>> head(df)
>     Y                       X      Z
> 1 0.0008094667  50     1
> 2 0.0012360955  50     1
> 3 0.0016627243  50     1
> 4 0.0020893531  50     1
> 5 0.0025159819  50     1
> 6 0.0029426108  50     1
>> contour(df$X, df$Y, df$Z)
> Error in contour.default(df$X, df$Y, df$Z) :
> increasing 'x' and 'y' values expected
> ```
> Y is increasing, whereas X is decreasing. How shall I set the function?
> Thank you
> 

Contour needs the Z data in a grid, with the X and Y data corresponding 
to rows and columns.  The interp::interp() function in the interp 
package should be able to convert your data to this format; see its help 
page.  An alternative is the akima::interp() function, which may have 
licensing issues.

Duncan Murdoch



More information about the R-help mailing list