gpt4 book ai didi

r - 如何将图片插入到 ggplot 图中的每个单独的条中

转载 作者:行者123 更新时间:2023-12-02 03:26:30 25 4
gpt4 key购买 nike

我正在尝试比较不同 NBA 新秀的不同统计数据,并且我认为如果我可以像 r/dataisbeautiful graphs 那样在图表末尾添加球员的脸部,图表看起来会很棒。 。我的代码目前是这样的:

a3 %>%
ggplot(aes(x = reorder(Player,
PPM),
y = PPM)) +
geom_bar(stat = "identity",
aes(fill = Player)) +
geom_text(aes(label = PPM), size = 3, position = position_dodge(width = 1),
hjust = -0.1) +
coord_flip() +
theme_minimal() +
xlab("Player") +
ylab("Points Per Minute") +
theme(legend.position = "none")

这就是我的图表当前的样子 like

最佳答案

您没有提供代表,所以我需要弥补一些。我可能会这样做。

library(tidyverse)
library(ggtextures)
library(magick)
#> Linking to ImageMagick 6.9.9.39
#> Enabled features: cairo, fontconfig, freetype, lcms, pango, rsvg, webp
#> Disabled features: fftw, ghostscript, x11

data <- tibble(
count = c(5, 6, 6, 4, 2, 3),
animal = c("giraffe", "elephant", "horse", "bird", "turtle", "dog"),
image = list(
image_read_svg("http://steveharoz.com/research/isotype/icons/giraffe.svg"),
image_read_svg("http://steveharoz.com/research/isotype/icons/elephant.svg"),
image_read_svg("http://steveharoz.com/research/isotype/icons/horse.svg"),
image_read_svg("http://steveharoz.com/research/isotype/icons/bird.svg"),
image_read_svg("http://steveharoz.com/research/isotype/icons/turtle.svg"),
image_read_svg("http://steveharoz.com/research/isotype/icons/dog.svg")
)
)

ggplot(data, aes(animal, count, fill = animal, image = image)) +
geom_isotype_col(
img_height = grid::unit(1, "null"), img_width = NULL,
ncol = 1, nrow = 1, hjust = 1, vjust = 0.5
) +
coord_flip() +
guides(fill = "none") +
theme_minimal()

reprex package于2019年11月3日创建(v0.3.0)

关于r - 如何将图片插入到 ggplot 图中的每个单独的条中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58677247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com