I would like to map OHS incidents over a PNG of a hospital floorplan using ggplot2. I have tried reading this non-geographic map in as a ggimage.
So far I have tried the following with the dataset (14462) observations that I have.
Example dataset
toy <- data.frame(patient_ID = c(1001,1001,1002,1003,1004),
SEX = c("M","M","F","F","F"),
phenotype = c("Psychiatric","Psychiatric", "Cardio",
"Cancer","Psychiatric"),
x = c(0.5737, 0.5737, 0.6968, 0.4704, 0.6838),
y= c(0.3484, 0.3484, 0.62, 0.5216, 0.2486))
I have tried reading the file in as a raster and then using ggmaps but the difficulty is no legend.
library(ggmap)
library(png)
library(ggplot2)
library(data.table)
toy <- fread("toy.csv")
# read in image
r <- readPNG("ICU-crop.png")
#use ggimage to convert to plot and add gender
ggimage(r, scale_axes = TRUE) +
geom_point(aes(x = x, y = y, colour = SEX), data = toy,
size = I(1), fill = NA)
I would really like to use ggplot but need the legend. I am not sure what other methods I can use to ggplot over a PNG.