Ggplot hot map not filling tiles

This (minimal, standalone) example is broken down:

require(ggplot2) 

min_input = c(1, 1, 1, 2, 2, 2, 4, 4, 4)
input_range = c(4, 470, 1003, 4, 470, 1003, 4, 470, 1003)
density = c(
    1.875000e-01,
    5.598958e-04,
    0.000000e+00,
    1.250000e-02,
    3.841146e-04,
    0.000000e+00,
    1.250000e-02,
    1.855469e-04,
    0.000000e+00)       

df = data.frame(min_input, input_range, density)

pdf(file='problemspace.pdf')
ggplot(df, aes(x=min_input, y=input_range, fill=density)) +
    geom_tile()
dev.off()

      

Production:

gapped tiles

Why are there large gaps?

+3


source to share


1 answer


There are gaps because you don't have data for all chunks. If you want to try filling them in, your only option is interpolation (unless you have access to additional data). In theory geom_raster()

(close relative geom_tile()

) supports interpolation. However, according to this github issue , this feature is currently not working.

As a workaround, however, you can use qplot, which is just a wrapper around ggplot:

qplot(min_input, input_range, data=df, geom="raster", fill=density, interpolate=TRUE)

      

If there is too much space between the points for which you have data, you will still fill in the gaps in your graph, but this will expand the range you can estimate for values.



EDIT:

Based on your example, this would be the output

enter image description here

As you can see, the vertical white band goes through the middle due to the lack of data points between 2 and 4.

+5


source







All Articles