Bir ggplot grafiğinde her bir çubuğa resim ekleme


9

Farklı istatistiklerde farklı NBA çaylaklarını karşılaştırmaya çalışıyorum ve r / dataisbeautiful grafiklerinde olduğu gibi, grafiğin sonuna oyuncunun yüzünü ekleyebilirsem grafiğin harika görüneceğini düşündüm . Kodum şu anda bu:

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")

Grafiğim şu anda böyle görünüyorsevmek


2
Bu blog gönderisini gördünüz mü, oldukça alakalı görünüyor: jcarroll.com.au/2019/08/13/ggtext-for-images-as-x-axis-labels
— Ben


Yanıtlar:


7

Reprex vermedin, bu yüzden birţey uydurmam gerek. Muhtemelen böyle yapardım.

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()

2019-11-03 tarihinde reprex paketi tarafından oluşturuldu (v0.3.0)


Teşekkürler, bu harika çalıştı! Ggplot (veri, aes (hayvan, saymak, doldurmak = hayvan, image = image & x))
— Pedro Guizar

Lütfen bunun için ayrı bir üst düzey soru gönderin.
— Claus Wilke


Bu çok faydalı. CRAN'da ggtextures almanın bir planı var mı?
— stevec

Hayır. Şimdi çok daha güçlü olan ggpattern var. github.com/coolbutuseless/ggpattern
— Claus Wilke
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.