这个问题与image() from the ggimage package be made to preserve the image aspect ratio?有关,但在我的应用程序中,我想使用与实际图像大小成比例的图像绘制一个散点图。
我想用geom_image()再现的图形(手工完成,用PPT完成)如下所示:

我按如下方式读取数据,并使用readPNG()在png包中获取图像大小:
> brains.dat <- file.path(folder, "brain-size.csv")
> brains <- read.csv(brains.dat, stringsAsFactors=FALSE)
> brains$class <- factor(brains$class)
>
> library(png)
>
> sizes <- t(sapply(brains$img, function(x) dim(readPNG(x))))
> brains$height <- sizes[,1]
> brains$width <- sizes[,2]
> brains
species class brain_weight neurons img height width
1 Capybara non-primate 48.2 0.30 capybara.png 31 70
2 Rhesus Macaque primate 69.9 1.71 rhesus.png 63 75
3 Western Gorilla primate 377.0 9.10 gorilla.png 71 95
4 Human primate 1232.0 16.30 human.png 98 117
5 African Bush Elephant non-primate 2848.0 5.59 elephant.png 98 168
> 我看不到在下面调用geom_image()中设置每个图像的高度和宽度的任何方法
library(ggimage)
library(ggplot2)
col <- ifelse(brains$class=="primate", "blue", "red")
ggplot(brains, aes(x=brain_weight, y=neurons)) +
geom_text(aes(label=species), color=col, hjust="inward") +
geom_image(aes(image=img)) + theme_bw()我从中得到的是所有大小相同的图像,我想是一样宽的。我忽略了为了更好地定位标签所需要的调整。

编辑:这是作为一个问题提交的https://github.com/GuangchuangYu/ggimage/issues/6。作者说,这还没有得到支持,但也许有一个解决办法?
发布于 2018-04-19 11:43:26
https://stackoverflow.com/questions/49798731
复制相似问题