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 data perfectly (image 3)
The code I am using is:
SolidReg<-ggplot(RhyShp[,c(13,15)], aes(x=Solidity, y=Reg) ) +
stat_density_2d(aes(fill = ..level..), geom = "polygon") +
labs(x = "Solidity", y = "Regularity") +
theme_classic()
RhyShp is the dataframe from my file 5_102_Rhy.csv used to generate images 1 and 2.
Does anyone know why the contour plot doesn't reflect the dataset? I am not sure why the code would work for one csv but not another....
thanks!
Turns out this was an issue with the data containing multiples of identical values which skewed the density without being discernible in the geom_point() plot. Once these duplicates were removed the density plot reflected the true density of the data.