R generate 2D histogram from raw data

后端 未结 6 1947
谎友^
谎友^ 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:14

    If you want it with a 2d contour, you can also use the package ggplot2. Some example code is shown in this question:

    gradient breaks in a ggplot stat_bin2d plot Adjusted slightly:

    x <- rnorm(10000)+5
    y <- rnorm(10000)+5
    df <- data.frame(x,y)
    require(ggplot2)
    p <- ggplot(df, aes(x, y)) 
    p <- p + stat_bin2d(bins = 20)
    p
    

    Sample Image

    Here's the output of the code above:

提交回复
热议问题