I want to plot pie charts at specific location on an image of the human body. I have tried to piece together code by following some related posts. But I"m stuck. imX and imY indicate the position on the body that I would like the pie charts then for each tax-rank, I would like a pie where each slice represents a tax_name, count_norm is the proportion.
Here is my dataframe below.
head(wholebody_cutLH)
tax_name tax_rank count_norm imX imY
9 Moraxellaceae NoseF_Jly2015 3.193710e-04 1.5 5.2
12 Neisseriaceae NoseF_Jly2015 1.234482e-01 1.5 5.2
18 Alcaligenaceae NoseF_Jly2015 3.399756e-05 1.5 5.2
Here is my code.
img <- readPNG( paste(dir,"aac_human_body.png",sep=""))
g <- rasterGrob(img, width=unit(1,"npc"), height=unit(1,"npc"), interpolate = FALSE)
ggplot(wholebody_cutLH) +
annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_bar(aes(x=imX, y=count_norm, fill=tax_name, width = 1, stat="identity")) +
coord_polar("y", start = 0)
I am getting errors that annotation_custom only works with cartesian coordinates, but I need to use polar for the pie.
BTW I don't have to use ggplot but wasn't quite sure how to do it with base R either.