R generate 2D histogram from raw data

后端 未结 6 1994
谎友^
谎友^ 2021-02-01 07:47

I have some raw data in 2D, x, y as given below. I want to generate a 2D histogram from the data. Typically, dividing the x,y values into bins of size 0.5, and count the number

6条回答
  •  灰色年华
    2021-02-01 08:00

    Bivariate density estimates can be done with MASS::kde2d, or KernSmooth::bkde2D (both supplied with the base R distribution). The latter uses an algorithm based on the fast Fourier transform over a grid of points, and is very fast. The result can be plotted with contour or persp or similar functions in other graphing packages.

    Using your data:

    require(KernSmooth)
    z <- bkde2D(df, .5)
    persp(z$fhat)
    

    enter image description here

提交回复
热议问题