作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试比较不同 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")
最佳答案
您没有提供代表,所以我需要弥补一些。我可能会这样做。
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/
我是一名优秀的程序员,十分优秀!