I am trying to categorise image asset performance in a Google ad and want to use geom_image()
to add the actual image to the plot so I know which one is performing best. I have added images to plots before, and it has worked so I am using the same basic code layout. My issue is that the images are being plotted as filled geoms and are coloured the same as my specified colour values:
Below is the code that I have used. I changed the actual images to an image of a ball for reprex purposes. When I run it like this, the issue persists. I suspect the issue is in how I am expressing things in aes()
but I am not sure how I should change it. Ideally the filled geoms would all be images of the ball.
# Packages
library(tidyverse)
library(ggimage)
library(ggchicklet)
# Create sample data
df <- data.frame(
Asset = c("running_wide", "biomechanicsMan_wide", "running_square", "mandelbrot_wide",
"mandelbrot_square", "lines_wide", "systems_square", "systems_wide", "lines_square"),
status = rep("Enabled", 9),
Asset_type = c("Image", "Image", "Square image", "Image", "Square image", "Image", "Square image", "Image", "Square image"),
Performance = c("Best", "Best", "Best", "Best", "Low", "Best", "Good", "Best", "Good"),
Asset_source = rep("Advertiser", 9),
val = rep(10, 9),
font_size = c(10, 10, 10, 10, 10, 10, 10, 10, 10),
asset_name = rep("ball", 9),
path = rep("https://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/Basketball.png/220px-Basketball.png", 9)
)
ggplot(df, aes(x = reorder(Asset, font_size), y = val, fill = Performance, colour = Performance)) +
geom_chicklet(width = 0.9, alpha = 0.3, size = 1) +
scale_fill_manual(values = c("Best" = "#D6AF36",
"Good" = "#A7A7AD",
"Low" = "#A77044"), name = NULL) +
scale_colour_manual(values = c("Best" = "#D6AF36",
"Good" = "#A7A7AD",
"Low" = "#A77044"), name = NULL) +
geom_image(aes(x = reorder(Asset, font_size), y = 1, image = path), size = 0.08) +
coord_flip() +
theme_void() +
theme(
legend.title = element_text(size = 16),
legend.text=element_text(size=13)
)
In your code, your fill the images with colors. Just move aes(fill = Performance, colour = Performance)
from ggplot()
to geom_chicklet()
line:
ggplot(df, aes(x = reorder(Asset, font_size), y = val)) +
geom_chicklet(aes(fill = Performance, colour = Performance), width = 0.9, alpha = 0.3, size = 1) +
scale_fill_manual(values = c("Best" = "#D6AF36",
"Good" = "#A7A7AD",
"Low" = "#A77044"), name = NULL) +
scale_colour_manual(values = c("Best" = "#D6AF36",
"Good" = "#A7A7AD",
"Low" = "#A77044"), name = NULL) +
geom_image(aes(x = reorder(Asset, font_size), y = 1, image = path), size = 0.08) +
coord_flip() +
theme_void() +
theme(
legend.title = element_text(size = 16),
legend.text=element_text(size=13)
)