R: Contour plots for marginal distributions with discrete variables

感情迁移 提交于 2020-01-03 05:26:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!