Take the 2-minute tour ×

I intend to plot x-y coordinates of a traced object with scatterplot.density to use colour to show the density of points in the scatterplot instead of just displaying the points in a smooth scatterplot (smoothScatter). When I run the following short segment of the trace:

x <- c(69.8, 69.8, 70.07, 70.87, 70.87,72.48,73.02, 73.02, 74.36, 74.63)
y <- c(97.99,97.45,96.91,96.11,96.91,96.91,97.72,99.06,100.94,103.36)
par(mfrow = c(1, 1))
scatterplot.density(x, y)

I get the following error:

Error in image.default(x = 1, y = z, z = matrix(z, nrow = 1, ncol = length(col)), : increasing 'x' and 'y' values expected

I can blot the points in a smoothScatter without a problem, but this would not help once I add the full trace with 1500 x-y coordinates.

Any suggestions and help with the scatterplot.density problem would be highly appreciated! Thanks!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

What I've found is that if the argument num.bins is high enough to seperate each point into a single bin then you will recieve the error. Try

scatterplot.density(x, y, num.bins=11)


scatterplot.density(x, y, num.bins=10)

the default is 64. That means 64 bins in the x axis and y axis. You either need to be lower you're bin number, add more points, or be content with the error. Hope that helps.

share|improve this answer
Thank you! That solved the problem. Also after including all other data points, it became obvious that 64 bins would be too detailed for the trace anyway. –  user2510541 Jun 22 '13 at 0:33

Your Answer


