Questions tagged [stat-density2d]

35 questions
1
vote
1 answer

How can I extract data from a kernel density function in R for many samples at one time

I have a very large data file (>300k rows) and each row is part of a unique sample (>3000 samples). I want to generate a kernel density estimator for each individual sample and extract relevant information (minimum value, maximum value, maximum…
Jesse
  • 244
  • 2
  • 15
1
vote
1 answer

How can I prevent stat density from interfering with my legend - R?

# Create data df and mapping df ---- maindf<-data.frame(x_coord=sample(1:100, 40, replace=T), y_coord=sample(1:100, 40, replace=T), action=sample(1:5, 40, replace=T), …
Matt
  • 45
  • 4
1
vote
0 answers

Find centre location coordinates in R - geospatial analysis

I am trying to find the centre coordinates of high-density areas in R. The dataset I have has about 1.5million rows and looks like this (dummy data) LATITUDE LONGITUDE val 1 35.83111 -90.64639 359.1 2 42.40630 -90.31810 74.5 …
hybrid
  • 1,255
  • 2
  • 17
  • 42
0
votes
0 answers

In R, is there a way to constrain stat_density_2d to a polygon/shape in an underlying JPEG?

In R, I am trying to run stat_density_2d on a dataset and include a jpeg (containing a polygon) underneath. However, I would like to constrain the analysis of stat_density_2d so that it fits completely within the polygon shown in the underlying…
0
votes
1 answer

Stat_Density func in R filling in multiple grid squares instead of a single one

I am trying to highlight single 1x1 degree grid squares on a map. It works highlighting individual grid squares for the first 1 squares but after highlight the 4th square it begins to highlight multiple groups of squares and I am not sure…
J_S_Moss
  • 21
  • 4
0
votes
0 answers

stat_density_2d in ggplot2: bandwidths must be strictly positive

I'm trying to plot kernel density estimates for my data, but I'm getting an error ("bandwidths must be strictly positive") because the 0.25 and 0.75 quantiles are the same. A solution for this in MASS::kde2d was presented here, but I'm unsure how…
user100351
  • 11
  • 4
0
votes
0 answers

r ggplot2 stat_density2d - how to change the bandwidth calculation to Sheather and Jones method

I'm creating two maps, one with contour lines and the other is a heatmap. I'm using the geom_density2d function to create the one with contour lines, and stat_density2d to create the heatmap. Note that geom_density2d does not seem to have the same…
Amy M
  • 967
  • 1
  • 9
  • 19
0
votes
2 answers

Heatmap with locations in R

I am trying to plot a heatmap of a country with some points that are probabilities of occurrence of a event. What I did up to now is next: library(raster) library(ggplot2) Uruguay <-…
0
votes
1 answer

cropping stat_density_2d output to a polygon

I am trying to use the stat_density_2d() function to create a heat map based on GPS coordinates and would like to crop the output to a polygon in ggplot(). Here is an example: x_coord <- c(-83, -82, -82, -83, -83) y_coord <- c(41, 41, 42, 42,…
user1997414
  • 189
  • 3
  • 10
0
votes
2 answers

stat_density_2d errors when trying to use with facet_wrap

I'm trying to plot a variable (rd2200w) vs elevation (Z). I'm also trying to overlay and fill density contours. This works great for the whole dataset. When I try to facet by another variable I run into errors. I've read of similar issues here…
Rob
  • 13
  • 3
0
votes
0 answers

Remove the lowest level/bin of stat_density_2d?

I have a contour graph/heat map of hockey shot locations that I have plotted on an image of a rink, but there is too much noise. Particularly the lowest bin is completely unnecessary and ruins the image. Is there a way to get rid of just this bin? I…
0
votes
0 answers

Stat_density_2d contour plot is choppy and layered. How to smooth it out?

I am trying to build a shiny app that shows NHL shot location data via a contour plot on an image of a hockey rink. I have cleaned that data and was able to successfully build a point plot that marks a point for each shot on goal. But when I try to…
0
votes
1 answer

stat_density_2d doesnt generate contours that match raw data

I have a plot showing the points in my data (image 1) and a contour plot produced using stat_density_2d (image 2) The contours clearly don't represent the raw data very well. I have used the same code to generate other contour plots that fit the…
0
votes
0 answers

Displaying counts instead of "levels" using stat_density2d

My objective is to portray the locations with varying numbers of traffic conflicts in a road intersection. My data consists of all the conflicts that we observed in a given time period at an intersection coded into a .CSV file with the following…
0
votes
0 answers

How do I make ggplot 2 density plot in R wrap over all plots instead of individual plots?

I'm having issues constructing multiple density plots so that the density is calculated relative to ALL the plots instead of relative to individual plots. I am trying to calculate strikes on fighters during the course of a fight. But, the 'Total'…