2

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.

alistaire
  • 42,459
  • 4
  • 77
  • 117
user2814482
  • 631
  • 1
  • 10
  • 28
  • Check out https://stackoverflow.com/questions/43984614/rggplot2geom-points-how-to-swap-points-with-pie-charts/44125392#44125392 or https://stackoverflow.com/questions/45411140/small-ggplot2-plots-placed-on-coordinates-on-a-ggmap/45417727#45417727 – Brian Dec 08 '17 at 05:09
  • 1
    See also [this](https://stackoverflow.com/a/47645727/4975218) or [this](https://stackoverflow.com/a/47613775/4975218) SO answer. In general, I think it's best not to draw pie charts in polar coordinates. – Claus Wilke Dec 08 '17 at 05:28
  • thanks. I've tried scatterpie and the ggforce method , I feel like I"m closer with both, but am still getting errors. I think I'll ask a new question about those ? – user2814482 Dec 08 '17 at 16:16
  • You can edit your current question, since you haven’t received any answers yet. Also, if you could provide a link to the image you use or make an example with a different, free image that would be helpful. – Claus Wilke Dec 08 '17 at 18:55

0 Answers0