Reputation: 21
I've used code that was working before (with other data) to visualize new data. Now, I get an error message. Since the code is working with other data, I suppose that something is different with my new data in a way stat_contour()
doesn't like.
This line of my code produces the problem:
stat_contour(aes(z=log_llh),bins=15,colour='black',size=0.5) +
The error message is:
Error in contourLines(x = sort(unique(data$x)), y = sort(unique(data$y)), : (list) object cannot be coerced to type 'double' Error in if (nrow(layer_data) == 0) return() : argument is of length zero
Here is a snippet of my data:
rec,foi,sensit,prev,log_llh,log_llh_prev,log_llh_decay,p_prev,p_decay,p_min
0.50,1.04,1.00,0.67532,-1329.744,-1068.151,-261.593,0.000000,0.000000,0.000000
0.50,1.05,1.00,0.67742,-1335.410,-1073.659,-261.751,0.000000,0.000000,0.000000
0.50,1.06,1.00,0.67949,-1341.070,-1079.136,-261.934,0.000000,0.000000,0.000000
0.50,1.07,1.00,0.68153,-1346.547,-1084.581,-261.967,0.000000,0.000000,0.000000
0.50,1.08,1.00,0.68354,-1352.441,-1089.995,-262.447,0.000000,0.000000,0.000000
0.50,1.09,1.00,0.68553,-1357.835,-1095.377,-262.457,0.000000,0.000000,0.000000
0.50,1.10,1.00,0.68750,-1363.231,-1100.729,-262.501,0.000000,0.000000,0.000000
0.60,0.01,1.00,0.01639,-737.232,-504.203,-233.029,0.000000,0.000000,0.000000
0.60,0.02,1.00,0.03226,-671.471,-438.418,-233.053,0.000000,0.000000,0.000000
0.60,0.03,1.00,0.04762,-639.377,-406.600,-232.777,0.000000,0.000000,0.000000
0.60,0.04,1.00,0.06250,-621.661,-388.539,-233.122,0.000000,0.000000,0.000000
0.60,0.05,1.00,0.07692,-611.319,-377.908,-233.411,0.000012,0.000000,0.000000
0.60,0.06,1.00,0.09091,-605.159,-371.891,-233.268,0.007365,0.000000,0.000000
0.60,0.07,1.00,0.10448,-602.492,-368.991,-233.501,0.239827,0.000000,0.000000
Somebody else had the problem before and there the problem was that the data matrix wasn't following a regular grid. My grid has regular increments of 0.1 (rec) and 0.01 (foi).
Does anyone have an idea what might be wrong?
PS: Plotting the exact same data with geom_tile(aes(fill=log_llh))
works perfectly fine, while stat_contour(aes(z=log_llh),bins=15,colour='black',size=0.5)
is still not working
Upvotes: 2
Views: 1179
Reputation: 1925
Googled around and found this: http://www.stat.cmu.edu/~brian/463/hw02/on-making-contour-plots.r They say:
Whatever generated this error, it does not tell us much about where the real problem lies...
It turns out that the problem is that the "stat_contour" function expects to find data on a regular grid of (x,y) values, and our data is not on any grid at all.
So you probably need to make sure your x
and y
are grid.
Upvotes: 1