diff --git a/src/statistics.jl b/src/statistics.jl index 9c0f4ff81..a8bd8ec2d 100644 --- a/src/statistics.jl +++ b/src/statistics.jl @@ -1749,8 +1749,9 @@ function apply_statistic(stat::JitterStatistic, rng = MersenneTwister(stat.seed) for var in stat.vars data = getfield(aes, var) - broadcast!(+, data, data, stat.range * (rand(rng, length(data)) - 0.5) .* span) - setfield!(aes, var, data) + outdata = Array(Float64, size(data)) + broadcast!(+, outdata, data, stat.range * (rand(rng, length(data)) - 0.5) .* span) + setfield!(aes, var, outdata) end end diff --git a/test/jitter.jl b/test/jitter.jl index a76d5b0b6..e11e68bfc 100644 --- a/test/jitter.jl +++ b/test/jitter.jl @@ -4,4 +4,6 @@ using Gadfly, DataArrays, RDatasets plot(dataset("datasets", "iris"), x=:SepalLength, y=:SepalWidth, color=:Species, Stat.x_jitter, Stat.y_jitter, Geom.point) - +# make sure type-coercion works properly, the `y` values here are integers +# but will be coerced into floats. +plot(x=rand(500), y=rand(1:4, 500), Stat.y_jitter(range=0.5), Geom.point)