r - geom_node_image() - ggraph 中节点的图像

标签 r ggraph ggimage

我正在尝试在 ggraph 网络中使用图像(例如国旗)。我一直想使用 ggimage 的 geom_image ,但是我认为该函数需要进行调整才能与 ggraph 一起使用,其中我们不指定 x 和 y 坐标。

library(tidygraph)
library(ggraph)
library(ggimage)

r <- create_notable('bull') %>%
  mutate(class = sample(letters[1:3], n(), replace = TRUE),
         image = "https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png")

ggraph(r, 'stress') + 
  geom_node_point() +
  geom_edge_link()


r %>% 
  as_tibble() %>%
  ggplot(aes(x = runif(nrow(.)), y = runif(nrow(.)))) +
  geom_image(aes(image = image))

# I would like this to work:
ggraph(r, 'stress') + 
  geom_node_image(aes(image = image)) +
  geom_edge_link()

最佳答案

确实是ggraph不需要您指定 X 和 Y 坐标,但这很方便。变量名称为xy 。您可以明确表示:

ggraph(r, 'stress') + 
  geom_node_point(aes(x = x, y = y))

这些变量可用于所有其他 ggplot相关功能,包括ggimage::geom_image() .

ggraph(r, 'stress') + 
  geom_edge_link() + 
  geom_image(aes(x = x, y = y, image = image))

enter image description here

关于r - geom_node_image() - ggraph 中节点的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65467871/

相关文章:

r - ggjoy 方面与 ggtree

r - 使用 tidytext 将字数大小作为图层添加到共现网络图表上的节点大小

r - 寓言预测数据集请求和功能

r - 使用 R 进行荷兰语情感分析

r - ggraph网络图: specify node coordinates

r - 如何将图像添加到 ggplot

r - 在 ggplot2 中使用 SVG 图像作为符号

r - 可以使用 ggimage 包中的 geom_image() 来保留图像纵横比吗?

r - JSON 键,使用 R 进行值格式化/选择一列作为键,另一列作为值

r - 在 ggraph/ggplot2 中将几何标签放置在圆形布局之外