Use ggplot to build a legend image

I would like to map OHS incidents over a PNG of a hospital site plan using ggplot2. I tried reading this non-geographic map as ggimage.

ICU Work Plan

So far, I have tried the following with the observations (14462) that I have.

Data set example

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 tried reading the file as a raster and then using ggmaps, but the difficulty is not a 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 you need a legend. I'm not sure what other methods I can use for ggplot over PNG.

+4
source share
1 answer

"" fullpage=FALSE ggimage(), :

ggimage(r, fullpage = FALSE, scale_axes = TRUE) +
 geom_point(aes(x = x, y = y, colour = SEX), 
            data = toy, size = I(1), fill = NA) +
  labs(x=NULL, y=NULL) +
  theme(axis.text=element_blank()) +
  theme(axis.ticks=element_blank())

enter image description here

, , , ( ).

+3

All Articles