When researching this answer, I tried to draw the image strip via geom_image()
from the ggimage package but couldn't get it to work. geom_image()
modifies the images aspect ratios, and I don't know how to prevent it from doing it (or whether that is even possible). It's also not clear to me in what units size
is measured. From how the code behaves, maybe it's in npc
coordinates running from 0 to 1, regardless of the ggplot2 coordinate system?
Here is the code I used:
require(ggimage)
df_img <- data.frame(phase = c("Interphase", "Prophase", "Metaphase", "Anaphase", "Telophase"),
image = c("http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_interphase.jpg",
"http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_prophase.jpg",
"http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_metaphase2.jpg",
"http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_anaphase2.jpg",
"http://www.microbehunter.com/wp/wp-content/uploads/2009/lily_telophase.jpg"))
df_img$phase <- factor(df_img$phase, levels=df_img$phase)
ggplot(df_img, aes(x = phase, y = 0, image = image)) + geom_image(size = 0.18)
And this is the resulting image:
This is what the image should look like:
Note: This is a question specifically about the behavior of ggimage. I know how to generate the correct image using other approaches, e.g. by using draw_image()
from cowplot.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…