Skip to content

Instantly share code, notes, and snippets.

@danielredondo
Last active September 8, 2020 09:56
Show Gist options
  • Save danielredondo/ec8fc9975516dc15441db108a75f4886 to your computer and use it in GitHub Desktop.
Save danielredondo/ec8fc9975516dc15441db108a75f4886 to your computer and use it in GitHub Desktop.
Script para reproducir el siguiente gráfico: https://twitter.com/dredondosanchez/status/1287779985596579841
library(readxl)
library(dplyr)
library(ggplot2)
library(cowplot)
library(magick)
# Para fuentes
library(extrafont)
# font_import()
loadfonts(device = "win")
notas <- read_excel("notas.xlsx",
range = "B3:D18", col_names = FALSE)
names(notas) <- c("nombre", "nota", "creditos")
notas <- notas %>%
filter(is.na(nota) == F) %>%
arrange(-nota) %>%
# Para añadir el número de créditos:
# mutate(nombre = paste0(nombre, "\n(", creditos, " créditos)")) %>%
mutate(nombre = factor(nombre, levels = nombre))
head(notas)
ggplot(notas, aes(y = nota, x = nombre, label = sprintf("%.1f", nota))) +
geom_col(fill = "firebrick1", col = "black", width = 1) +
geom_text(color = "white", family = "Bahnschrift", fontface = "bold", size = 4.5, nudge_y = -0.5) +
geom_text(aes(label = nombre), hjust = 1, color = "white", lineheight = 0.9, fontface = "bold",
family = "Bahnschrift", size = 4, nudge_y = -0.95) +
xlab("") +
ylab ("") +
ggtitle("Máster Universitario Oficial en Ciencia de Datos e Ingeniería de Computadores") +
coord_flip() +
theme_classic() +
labs(caption = "@dredondosanchez") +
theme(
axis.ticks = element_blank(),
axis.line = element_blank(),
axis.ticks.length = unit(0, "null"),
text = element_text(family = "Bahnschrift"),
axis.text = element_text(color = "black"),
axis.text.y = element_blank(),
axis.text.x = element_text(size = 11),
plot.title = element_text(face = "bold", hjust = .6),
) -> grafico
grafico
# Añadir imagen de la Universidad de Granada
ggdraw() +
draw_plot(grafico) +
draw_image("https://raw.githubusercontent.com/danielredondo/TFM_ciencia_de_datos/master/documento/logos/ugr.png", y = .35, x = .37, scale = .2)
ggsave("notas.png", width = 8, height = 5, dpi = 300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment