geom_image

library("ggplot2")
library("ggimage")

set.seed(2017-02-21)
d <- data.frame(x = rnorm(10),
                y = rnorm(10),
                image = sample(c("https://www.r-project.org/logo/Rlogo.png",
                                 "https://jeroenooms.github.io/images/frink.png"),
                               size=10, replace = TRUE)
                )

ggplot(d, aes(x, y)) + geom_image(aes(image=image), size=.05)

ggplot(d, aes(x, y)) + geom_image(aes(image=image), size=.05, by='height')

ggplot(d, aes(x, y)) + geom_image(image=d$image[1])

d$size=seq(.05, .15, length.out=10)
ggplot(d, aes(x, y)) + geom_image(aes(image=image, size=I(size)))

ggplot(d, aes(x, y)) + geom_image(aes(image=image), color="firebrick")

geom_pokemon

ggplot(d, aes(x, y)) + geom_pokemon(aes(image=ifelse(x>0, 'pikachu', 'tauros')), size=.1)

geom_emoji

set.seed(123)
iris2 <- iris[sample(1:nrow(iris), 30),]
model <- lm(Petal.Length ~ Sepal.Length, data=iris2)
iris2$fitted <- predict(model)

ggplot(iris2, aes(x = Sepal.Length, y = Petal.Length)) +
  geom_linerange(aes(ymin = fitted, ymax = Petal.Length),
                 colour = "purple") +
  geom_abline(intercept = model$coefficients[1],
              slope = model$coefficients[2]) +
    geom_emoji(aes(image = ifelse(abs(Petal.Length-fitted) > 0.5, '1f622', '1f600')))

geom_phylopic

ggplot(d, aes(x, y)) + geom_phylopic(image = "500bd7c6-71c1-4b86-8e54-55f72ad1beca", size = .1) +
    geom_phylopic(image="0174801d-15a6-4668-bfe0-4c421fbe51e8", size=Inf, alpha=.6, color='steelblue')

geom_flag

f <- system.file("extdata/medals.txt", package="ggimage")
medals <- read.table(f, header=TRUE)
p <- ggplot(medals, aes(Country, count)) + geom_col(aes(fill = medal), width = .8)

p + geom_flag(y = -2, aes(image = code)) +
    coord_flip() + expand_limits(y = -2)  +
    scale_fill_manual(values = c("Gold" = "gold", "Bronze" = "#cd7f32", "Silver" = "#C0C0C0"))

geom_icon

d$icon=sample(c('power', 'wifi', 'pie-graph', 'usb'), 10, replace=TRUE)
ggplot(d, aes(x,y)) + geom_icon(aes(image=icon))

geom_subview

library(tibble)
dd <- data.frame(x=LETTERS[1:3], y=1:3)
pie <- ggplot(dd, aes(x=1, y, fill=x)) + geom_bar(stat="identity", width=1) + coord_polar(theta="y") +
    theme_void() + theme(legend.position="none") + theme_transparent()

df <- data_frame(x = sample(2:9),
                 y = sample(2:9),
                 width = sample(seq(0.5, 3, length.out=length(x))),
                 pie = list(pie))
p <- ggplot(data=data.frame(x=c(0, 10), y=c(0, 10)), aes(x, y))+geom_blank()
p + geom_subview(aes(x=x, y=y, subview=pie, width=width, height=width), data=df)