Questions tagged [stat-density2d]
35 questions
5
votes
1 answer
stat_density2d - What does the legend mean?
I have a map done in R with stat_density2d. This is the code:
ggplot(data, aes(x=Lon, y=Lat)) +
stat_density2d(aes(fill = ..level..), alpha=0.5, geom="polygon",show.legend=FALSE)+
geom_point(colour="red")+
geom_path(data=map.df,aes(x=long,…

Nicholas
- 3,517
- 13
- 47
- 86
3
votes
0 answers
Why does stat_density2d not always depict densities correctly?
I am currently working on a project, and so far I have extracted data.
Im in the works of visualising some of it. Thats where the issue starts.
I have an issue with ggmap density-plotting, especially in areas with smaller amounts of points.
I can…

R. Alexander
- 31
- 3
3
votes
0 answers
How do I stop the stat_density2d in R from plotting on the left-hand side of my boundary line?
I have created a code to make a scatter plot combined with a density plot. For several samples, I have set a boundary at some value. The scatter plot (geom_point) does not plot on the left-hand side of the boundary, whereas the density plot…

LiWa
- 51
- 2
3
votes
1 answer
How to modify ggplot2 stat_density_2d contour plot density scaling?
I'm working with a two column table that I am trying to make a density contour plot out of. "HiChIP_VillusvsCrypt" is the x axis and "RNAseq_VillusvsCrypt" is the y axis.
If you see in this attached image, there is a legend with the density scaling…

Rohit
- 31
- 3
3
votes
1 answer
Adding a 3rd Variable to a stat_density_2d Plot
Below is code and a dataset of a stat_density_2d plot I created in R.
library(ggplot2)
topKzone <- 3.5
botKzone <- 1.6
inKzone <- -0.95
outKzone <- 0.95
kZone <- data.frame(
x=c(inKzone, inKzone, outKzone, outKzone, inKzone),
y=c(botKzone,…

Nate Walker
- 217
- 2
- 12
2
votes
1 answer
ggplot2 stat_density_2d: how to fix polygon errors at the dataset bounding box edges?
I am analysing my sfc_POINT dataset using ggplot2::stat_density_2d. I seems, though, that the resulting polygons get all wonky at the edge of the dataset bounding box. For whatever reason, ggplot2 can't seem to draw polygons further than the source…

Vesanen
- 387
- 1
- 5
- 13
2
votes
0 answers
Density-2d plot on top of a map with ggmap
I want to produce a 2d-density plot based on spatial point data. In the background I want to show an open map (e.g. stamen terrain). Besides I want to plot the borders of Austria. Both datasets (data points and border) are shapefiles in EPSG 4326.
I…

Chris
- 21
- 2
2
votes
3 answers
How can I delete the background in stat_density_2d?
I am trying to make density maps in R using the function stat_density_2d, but I would like to remove the background color for which the density is null. I tried changing the limits for the density, but when moving the limits from [0,5] to [0.1, 5],…

Khadija
- 23
- 2
2
votes
0 answers
How can I decide on number of bins in geom plots
I have a dataset with close to a million records (coordinates). While plotting that in a map using R, when I use 'geom_point' to plot the data, everything works fine. Then When I plot a density plot using 'stat_density2d', I hardly get any values…

Visahan
- 1,130
- 2
- 14
- 35
1
vote
2 answers
Plot only top layers of ggplot stat_density_2d/geom_density_2d in R
I'm trying to generate a contour plot with ggplot in R, but keeping only the top layers of the plot. So for instance, with the following toy data:
df <- data.frame(x=rnorm(2000, 10, 3), y=rnorm(2000, 10, 3))
stat_density_plot <- ggplot(df, aes(x,…

Andrea
- 77
- 1
- 7
1
vote
0 answers
Why is ggplot cropping the density estimation laid over my map?
I'm trying to overlay geocoded citizen complaints onto a map of Chicago using ggplot. Due to overplotting, it seems like stat_density2d is a good visualization option.
I am able to generate the image, but for some reason the edge of the density plot…

Alonninos
- 11
- 3
1
vote
1 answer
R: how to combine color gradient on y-axis with density map?
Is it possible to combine a density 2D map, showing color intensity depending on the density of points values, with a color gradient related to y-axis? In other words on the following example, is it possible to choose a color_gradient from red for…

user15777046
- 11
- 1
1
vote
0 answers
Adding another variable information or adding weight into stat_density_2d
Below is a simple code to produce stat_density_2d plot of X~Y.
plot_data <-
data.frame(X = c(rnorm(300, 3, 2.5), rnorm(150, 7, 2)),
Y = c(rnorm(300, 6, 2.5), rnorm(150, 2, 2)),
Z = c(rnorm(300, 60, 5), rnorm(150, 40,…

user236321
- 95
- 1
- 5
1
vote
0 answers
ggplot2: identity of points in stat_density2d contours/bins
I am trying to ascertain the identity of the data points in the top two (i.e. innermost) contours, as given by stat_density2d(). How can I retrieve the data point ids? For example:
set.seed(1235)
dat <-…

brian
- 85
- 7
1
vote
1 answer
producing heat map over Geo locations in R
I want to produce heat map based on some geo-location data on top of the US map using r.
The following plot is created over the US map where I used geom_polygon() and geom_point().
How can I convert this to a heat map to get something as follows…

temp
- 82
- 1
- 10