jespermaag / gganatogram

Create anatograms using ggplot2
379 stars 52 forks source link

overlaying data #35

Open antoine4ucsd opened 1 year ago

antoine4ucsd commented 1 year ago

Hello I am a big fan of your package : simple and efficient! for my new project, I would like to plot diagram on top of the human body based on the coordinate of the organs... the first thing I did was to try to find the centroids of these organs.. I did the following although it is probably not ideal... (all suggestions are welcome)


df_cat<- data.frame()
for(i in 1:length(unique(names(hgMale_list)))){
        organ=unique(names(hgMale_list))[i]
        coordinates <- hgMale_list[i]
        lat=mean(coordinates[[1]]$X1,na.rm=T)
        lon=mean(coordinates[[1]]$X2,na.rm=T)
        df<- cbind(organ,lat,lon)
        df_cat=rbind(df_cat,df)

}

then is the tricky part. I do have my 'background' body with


organPlot <- data.frame(organ = c("heart", "aorta", "spleen", "brain", "liver", "duodenum", "colon", "prostate"), 
                        type = c("circulation", "circulation",  "circulation", "nervous system", "digestion", "digestion", "digestion",'reproductive'), 
                        colour = c("#F08080", "#F08080", "#F08080", "#c6e2ff", "#FDE1C1", "#D3EBED", "#57BFC5",'#F39325'), 
                        value = c(10, 5, 1, 8, 2, 5, 5,5), 
                        stringsAsFactors=F)
plot1 <- gganatogram(data=organPlot, fillOutline='white', organism='human', sex='male', fill="colour")+theme_bars()
plot1

but I would like to overlay a pie chart (ggplot) on top of a given organs a simple geom_point works

plot1+geom_point(aes(x=52.64,y=-4.84),size=5)

but what would you suggest to add another ggplot 'nested' /'on top' of the body? if you can think about alternative ways to do that, all ideas are very welcome!

thank you again for making this package available

Here's an example with 2 plots...