如何在一张图上绘制多张图像?

man*_*nro -2 r ggplot2 plotly

我想这样做是因为它对于在 R 中制作“绘图”很有用。

我想看到什么,例如:

在此输入图像描述

我有一个来自“boshek”的解决方案ggimage,但它有点有限。

我试着用plotly.

 no_axis <- list(
           title = "",
           zeroline = FALSE,
           showline = FALSE,
           showticklabels = FALSE,
           showgrid = FALSE
      )
 plot_ly() %>%
     layout(title = 'Quantity of cars in West Europe countries', xaxis = no_axes, yaxis = no_axes, 
         images = list(
             source = "https://jeroen.github.io/images/superfrink.gif",
             x = 1, y = 0.5, 
             sizex = 3, sizey = 2,
             xref = "x", yref = "y", 
             xanchor = "left", yanchor = "bottom"
         )
     )
Run Code Online (Sandbox Code Playgroud)

我只能添加一张图片,无法添加带有文本的标签。

bos*_*hek 5

一个超级基本的实现,但ggimage包是你的朋友:

library(ggimage)
library(ggplot2)
library(forcats) ## to reorder the labels

d <- data.frame(
  height = c(150, 350, 950),
  x = c("Luxembourg", "Spain", "France"), y = 1
)

## whatever you want
img <- "https://jeroenooms.github.io/images/frink.png"

ggplot(d, aes(x = fct_reorder(x, height), y = y)) +
  geom_image(aes(
    image = img,
    size = I(height / 1000)
  ), by = "height") +
  labs(title = " Quantity of cars in West Europe Countries") +
  theme_void() +
  theme(axis.text.x = element_text())
Run Code Online (Sandbox Code Playgroud)