How to draw a 2D human body?

380 views
Skip to first unread message

Ramiro Magno

unread,
Jun 7, 2021, 7:51:23 PM6/7/21
to ggplot2
Hi ggplot2 community,

I am not even sure if the ggplot2 is the appropriate tool in the R ecosystem for this task, so feel free to suggest to look elsewhere if that makes more sense.

Very simply, I'd like to draw graphics such as this human body:

human_body.jpg

I have in mind bodies of other species too. So would there be a mechanism to make the model in SVG, and then somehow implement a geom for it?? Does it even make any sense?

I am an avid ggplot2 user but I have never extended ggplot2 myself. Yet, I would not mind learning it if you think this would be a sensible approach...

Any feedback is truly appreciated.

Ramiro

Ron Crump

unread,
Jun 8, 2021, 3:35:16 AM6/8/21
to Ramiro Magno, ggplot2
Hi Ramiro,

> I am not even sure if the ggplot2 is the appropriate tool in the R
> ecosystem for this task, so feel free to suggest to look elsewhere if
> that makes more sense.

If I were you, I'd probably ask this on community.rstudio.com
which is where they encourage people to ask their ggplot questions
these days (Hadley Wickham works at RStudio), but also because
you may be able to get more discussion going there as you don't
have a specific problem that you need help with. You might want
to describe what you want to achieve and why to engage with people
though.

> Very simply, I'd like to draw graphics such as this human body:
>
> human_body.jpg

Pretty. But why? A one off? Or do you need to regularly draw
human bodies with different bits highlighted or filled in
accordance with some data?

> I have in mind bodies of other species too. So would there be a
> mechanism to make the model in SVG, and then somehow implement a geom
> for it??

I guess if you had the patience you could define polygons for each
of the elements (you'd need to get the coordinates from the image).

But why do you want to do this in ggplot? If I were doing it
I'd try bitmap tracing in inkscape then manually refining it there.
Or, as a LaTeX user, I'd think about getting it from inkscape as
TiKz code if I wanted to be able to include it my LaTeX documents
frequently.

Not sure what value a geom would have. You might need to describe
what use case you see for it.

> Does it even make any sense?

It isn't something I'd do. But then, there are many useful things
that I'd never have thought of doing.

Best wishes,
Ron

Konstantinos L. Papageorgiou

unread,
Jun 8, 2021, 3:56:41 AM6/8/21
to Ron Crump, Ramiro Magno, ggplot2
Hello Ramiro,
you can either treat the body as background image, either raster or
scalable as statoc
https://rpkgs.datanovia.com/ggpubr/reference/background_image.html
https://stackoverflow.com/questions/61387217/use-svg-images-as-symbols-in-gglot2
https://www.stat.auckland.ac.nz/~paul/Reports/grImport/grimport-gridsvg-export/grimport-gridsvg-export.html

or if you have the human body as coordinates you can also fully plot it.

Ramiro Magno

unread,
Jun 8, 2021, 4:46:33 AM6/8/21
to Konstantinos L. Papageorgiou, Ron Crump, ggplot2
Hi Ron and Konstantinos,

Thank you for your answers.

It would not be a one-off task.

Let me be more specific and describe my use case more explicitly.

Not sure if you are familiar with gene expression, and spatial detection of gene expression? But there is this experimental technique---in situ hybridization--- that allows you to detect (kind of in an on/off fashion) where the product of a gene is being produced in a small anatomical region, tissue or embryo.

Example: Expression of MYOD1 gene in the chick embryo: http://geisha.arizona.edu/geisha/search.jsp?entrez_gene=454491. (This is from the GEISHA project)

snap.png

Now, also look at this drawing with some developmental stages of the chick embryo (from the book The Atlas of Chick Development):

snap.png

I would like to have a programmatic way of drawing vector illustrations for each developmental stage where certain regions (areas delimited by polygons perhaps?) are highlighted with certain aesthetics (color, alpha, perhaps even a color gradient...).

Being able to draw such pictures would not just be prettier. It would have other advantages. First, it would allow me to communicate more effectively where a certain gene is expressed, usually in situ hybridization images can be difficult to interpret if you are not familiar with the embryo aspect. Moreover, it would allow me to combine the expression locations of more than one gene, which is something we currently do not have directly from those pictures.

The data for where a gene is expression at what stage is something that the GEISHA project does provide as a tabular file: expression.txt (in http://geisha.arizona.edu/geisha/downloads.jsp).

Sorry for the long email. I hope I conveyed the idea now. This would be extendable to other model organisms, such as the drosophila, mouse, etc..


Konstantinos L. Papageorgiou

unread,
Jun 8, 2021, 5:33:17 AM6/8/21
to Ramiro Magno, Ron Crump, ggplot2

Hi Ramiro,
interesting project u have there..
So yes certainly you can make all these in ggplot.
the geomery you need is called geom_polygon https://ggplot2.tidyverse.org/reference/geom_polygon.html
for each "comic" drawing that is decomposed into polygons having a different class
imagine data of the form x,y, class
x,y denote the point of the polygon and the class some string to group the points together as well as denote the color during drawing.
Your task is very close to drawing world maps.
data.tables and ggplot would most probably be your two close friends in this

with ggplot there is nearly nothing you can't do and at the same time render on svg, pdf, png ....

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ggplot2/CAFHVhtCxPbxzvAVWapKX-6hL7CkjS3ktF3fUtLKV0WQv6%3DQveQ%40mail.gmail.com.

Ramiro Magno

unread,
Jun 8, 2021, 6:38:21 AM6/8/21
to Konstantinos L. Papageorgiou, Ron Crump, ggplot2
Hi Konstantinos,

Thank you for your suggestions on using geom_polygon.

I also reached out to Thomas Pedersen (as you probably know, the author of many graphics-related packages) by email and he was so kind as to point me to this package by Athanasia Mowinckel: https://github.com/ggseg/ggseg.

ggseg looks like it's very close to my use case, do you think? Just like you said, my task is close to drawing world maps. And I just checked that indeed ggseg uses the R package sf (simple features) as dependency, so probably I should try to build something on top of that? Would you think that would be better compared to using geom_polygon directly?

Happy to hear your thoughts on this.

Manuel Spínola

unread,
Jun 8, 2021, 7:12:22 AM6/8/21
to Ramiro Magno, ggplot2
Hi Ramiro,

How about gganatogram?

Manuel

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.cr
mspin...@gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río
Institutional website: ICOMVIS

Ramiro Magno

unread,
Jun 8, 2021, 8:12:20 AM6/8/21
to Manuel Spínola, ggplot2
Hi Manuel,

On the surface, this looks spot on!

Thank you.

Konstantinos L. Papageorgiou

unread,
Jun 8, 2021, 11:20:37 AM6/8/21
to ggp...@googlegroups.com

nice thanks for keeping us in the loop

Konstantinos L. Papageorgiou

unread,
Jun 8, 2021, 11:25:17 AM6/8/21
to Ramiro Magno, Manuel Spínola, ggplot2

Also stumbled on this which potentially could allow you to import any svg you may found in the net and then do whatever you like with ggplot
- https://rdrr.io/cran/StratigrapheR/man/pointsvg.html

Ramiro Magno

unread,
Jun 8, 2021, 11:31:04 AM6/8/21
to Konstantinos L. Papageorgiou, Manuel Spínola, ggplot2
Cool, thanks! 

Kamil Slowikowski

unread,
Jun 16, 2021, 12:08:28 PM6/16/21
to ggplot2
There is a javascript project that might interest you, created by Fritz Lekschas:
Screenshot 2021-06-16 at 12.07.35 PM.png

Ramiro Magno

unread,
Jun 16, 2021, 1:10:09 PM6/16/21
to Kamil Slowikowski, ggplot2
Thank you so much Kamil!

This is really interesting.

You received this message because you are subscribed to a topic in the Google Groups "ggplot2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ggplot2/zaPGNS3g3Ko/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ggplot2+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ggplot2/aa41de2a-7196-479f-a3b0-73dafe1de4a5n%40googlegroups.com.

Kamil Slowikowski

unread,
Jul 22, 2021, 3:43:07 PM7/22/21
to ggplot2
I just stumbled into shinyBody by Maya Gans: https://github.com/MayaGans/shinyBody

Thought you might like it.

Screenshot 2021-07-22 at 3.42.39 PM.png
Reply all
Reply to author
Forward
0 new messages