问题
I am given a dataset with various numeric variables. I'll try to plot for each combination of two variables a contour/heat map plot, which shows the distribution/density of datapoints with respect to the corresponding pair. For example,
ggplot(data, aes(x=var1, y=var2) ) +
stat_density_2d(aes(fill = ..density..), geom = "tile", contour = FALSE )+
scale_fill_gradient2(low="darkblue",high="darkred",mid="white",midpoint=0.005)
This results in the following picture
The issue is now:
My data, respectively the variables are only taking integer values, such that the plot has gaps respectively valleys in between.
Is there a better way to plot this in this situation? E.g. somehow smooth it inbetween the integer values or define a grid-size of 1?
As dataset one can for example take the dataset "freMTPL2freq" from the "CASdatasets" library and take the variables "VehAge" and "DrivAge".
来源:https://stackoverflow.com/questions/54708124/r-contour-plots-for-marginal-distributions-with-discrete-variables