I have rasterLayers that contain digital temperature data from an airborne IR camera. I can create a false color plot using ggplot. I would like to save the plot as a PNG with values of zero being transparent and/or create KML files for displaying on Google Earth.
I have been creating the PNG files in a loop with the code below. "heatMapPlot" is the function that uses ggplot to create the plot - it works. It sets na.value <- "#000000" so that I can detect if borders are added by print( p ) - they are.
png(file = fname, width = NCOLS, height = NROWS)
p <<- heatMapPlot(
theRasterLayer[[passNum]], colors, colorvalues
)
print(p)
dev.off()
If I plot p
> plot(p)
The result is exactly what I want but it is not saved.
Writing p to a file with print(p) adds a wide white border around 80 pixels wide around the plot and the plot is scaled to fit into the width and height. This is unacceptable for placing on Google Earth. The image below shows the output ggplot output in the black area, the white border was added by "print(p)". (Feels like auto correct)
How can I write the PNG to disk without the border and/or how can I convert the ggplot output to a KML?
EDIT I think this is not possible, I'll go straight to KML files but there is a palette problem.