Home > Blockchain >  Issues with density plots in R using geom_density_2d_filled
Issues with density plots in R using geom_density_2d_filled

Time:12-10

I have x and y positions and I want to draw a density map using ggplot however, it gives me the following error:

Error in seq_len(n) : argument must be coercible to non-negative integer In addition: Warning messages: 1: Computation failed in stat_density2d_filled(): bandwidths must be strictly positive 2: In min(x, na.rm = na.rm) : no non-missing arguments to min; returning Inf 3: In max(x, na.rm = na.rm) : no non-missing arguments to max; returning -Inf 4: In max(f) : no non-missing arguments to max; returning -Inf

Both x and y are numeric and there are no missing values. But I still keep getting the same error. The code I am using is:

  ggplot(Fish, aes(x=xpos, y=ypos))   
geom_density_2d_filled(aes(fill = ..level..), alpha=0.85, breaks= c(0,10^-5, 10^-4,10^-3,10^-2,10^-1,1),
                       contour_var = "ndensity")  
scale_fill_brewer(type = "seq",palette = "Spectral", direction = -1)

This code works fine for other data sets where I have x and y positions for other fishes. But this data set is giving errors.

The link to the CSV file with data is: enter image description here

  • Related