Are there other ways that are more elegant or more efficient?
Credit: markhw
library(tidyverse)
data("starwars")
# Contagem de espécies
species <- starwars %>%
count(species) %>%
filter(!is.na(species) & n > 1) %>%
arrange(-n) %>%
mutate(species = factor(species, species))
# Carregar logo PNG
logo <- grid::rasterGrob(
png::readPNG("C:/Users/czarg/OneDrive/Documents/github/logo.png"),
interpolate = TRUE)
# Gráfico de barras
ggplot(species, aes(x = species, y = n)) +
geom_bar(stat = "identity") +
theme_light() +
coord_cartesian(clip = "off") +
theme(plot.margin = unit(c(1, 1, 3, 1), "lines")) +
annotation_custom(logo, xmin = 6.5, xmax = 8.5, ymin = -5, ymax = -8.5)