I am trying to create a gender-based pictogram chart using ggplot2 in R, where the size of the two pictograms should be proportional to the frequency of each gender. However, I am encountering some errors and would appreciate some help in resolving them. Here is what i tried so far:
*edit: I have changed the code on Mark's advice so that it is reproducible.
library(ggplot2)
library(ggimage)
# Creating example Dataset----------------------------------------
sum <- matrix(c(36, 12), 1, 2, dimnames=list("Anzahl",c("male", "female")))
rel_sum <- sum / sum(sum)
# Selecting symbols and colors -----------------------------------------
par(family = "Segoe UI Symbol")
symbol_m <- "\u2642"
symbol_w <- "\u2640"
# Colors
f1 <- rgb(255, 255, 204, maxColorValue = 255)
f2 <- rgb(161, 218, 180, maxColorValue = 255)
colour_m <- f1
colour_w <- f2
p <- ggplot() +
xlim(0, 2) +
ylim(0, 1) +
theme_void()
p <- p +
geom_text(
aes(x = 0.5, y = 0.5, label = symbol_m, color = colour_m),
size = 10,
hjust = rel_sum["male"]
) +
geom_text(
aes(x = 1.5, y = 0.5, label = symbol_w, color = colour_w),
size = 10,
hjust = rel_sum["female"]
)
print(p)
I have already tried a few things and I am not sure whether these ggplot functions work as i use them here.
As i said, i want to create a dynamically sized gender-based pictogram chart using ggplot2. The problem with the above code is that although i get a graphic with coloured pictograms, on the one hand they do not have the right colours and above all unfortunately they are both the same size.
Does anyone have any ideas what else i could try?
Any assistance would be highly appreciated. Thank you!