Skip to content

Instantly share code, notes, and snippets.

@gonzalezgouveia
Created April 24, 2019 14:03
Show Gist options
  • Save gonzalezgouveia/6b0ee2c47b3245c0b270dcba8a195079 to your computer and use it in GitHub Desktop.
Save gonzalezgouveia/6b0ee2c47b3245c0b270dcba8a195079 to your computer and use it in GitHub Desktop.
# hacer objeto de grafica
p <- population_tidy %>%
ggplot(aes(ordering, group = country)) +
# utilizar geom_tile en lugar de geom_bar
geom_tile(aes(y = population10/2,
height = population10,
width = 0.9, fill=country), alpha = 0.9) +
# texto en las barras
geom_text(aes(y = population10, label = paste(as.character(round(population10)), 'M')),
vjust = 0.4, hjust = 0.55, size = 7) +
geom_text(aes(y = 0, label = country),
vjust = 0.4, hjust = 0.0, size = 7) +
# nombres
labs(title = paste("Población Año ",
'{closest_state}', sep=""),
subtitle = 'Para paises de habla hispana',
x = '', y = '') +
# para que las barras sean horizontales
coord_flip(clip = 'off') + # clip = 'off' para sacar texto de márgenes
# modificando algunos elementos del tema principal
theme(plot.title = element_text(size = 22),
plot.subtitle = element_text(size = 16),
axis.ticks.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(),
legend.position = "none")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment