stat_density2d seems don't like discrete data. My code following cannot be plotted, and have such errors on R 2.15.2:
Error in contourLines(x = sort(unique(data$x)), y = sort(unique(data$y)), : no proper 'z' matrix specified In addition: Warning messages: 1: Removed 10000 rows containing non-finite values (stat_contour). 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf
On R 2.15.3, the error is:
Error in function (x, y, h, n = 25, lims = c(range(x), range(y))) :
bandwidths must be strictly positive
Probably because of the limitation n = 25.
a<-url("http://www-personal.umich.edu/~ajing/Files/TestData.RData")
load(a)
library(ggplot2)
p1<-ggplot(myd, aes(x=xvar,y=yvar)) + stat_density2d(aes(fill=..level..), geom="polygon")
gt <- ggplot_gtable(ggplot_build(p1))
Anyway to avoid this error? Or other recommended 2D histogram plots?
As I need two marginal histograms, ggplot is better than filled.contour for me.