Can geom_image() from the ggimage package be made to preserve the image aspect ratio?

十年热恋 提交于 2019-12-02 00:03:40
ggplot(df_img, aes(x = phase, y = 0.25, image = image)) +
  geom_image(size = 0.5, by="height")+
  scale_size_identity()

will produce

If by is specified, size is mapped and interpreted as npc in the data space, either as width or height, and the aspect ratio maintained for the current device (not after resizing). If size is Inf, the picture stretches to fill the whole panel.

A rather "raw" solution:

p <- ggplot(df_img, aes(x = phase, y = 0, image = image)) + 
     geom_image(size = 0.18) +  coord_fixed()

g <- ggplotGrob(p)   
for (k in 1:length(g$grobs[[6]]$children[[3]]$children)) {
  g$grobs[[6]]$children[[3]]$children[[k]]$height <- unit(0.8,"native")
}
library(grid)
grid.draw(g)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!