Skip to content

Instantly share code, notes, and snippets.

@gonzalezgouveia
Last active July 3, 2019 19:17
Show Gist options
  • Save gonzalezgouveia/8a5a43400978ca9e130f2a63b892fc39 to your computer and use it in GitHub Desktop.
Save gonzalezgouveia/8a5a43400978ca9e130f2a63b892fc39 to your computer and use it in GitHub Desktop.
# Hecho con gusto para
# Twitter #DatosDeMiercoles por @R4DS_es
# Por Rafa @GonzalezGouveia
# CURSO de R con RSTUDIO en YOUTUBE --> https://bit.ly/2RRWUPl
library(tidyverse)
# install.packages("cranlogs")
library(cranlogs)
library(ggthemes)
library(ggrepel)
# descargamos datos con la librería cranlogs
cran_tidy <- cran_downloads(package = c("ggplot2",
"dplyr",
"tidyr",
"readr",
"purrr",
"tibble",
"stringr",
"forcats"),
from = "2019-01-01",
to = "2019-06-30")
# calculamos la suma total para el porcentaje
sumatotal <- sum(cran_tidy$count)
# reagrupamos los datos por paquete
cran_tidy_group <- cran_tidy %>%
group_by(package) %>%
summarise(suma = sum(count)) %>%
ungroup() %>%
arrange(desc(package)) %>%
mutate(prop = suma/sumatotal,
labypos = cumsum(prop) - 0.5*prop)
# creamos la gráfica
cran_tidy_group %>%
ggplot(aes(x = 2, y = prop, fill = package)) +
geom_bar(width = 1,
stat = 'identity',
color = 'black') +
geom_label(aes(x = 2.2,
y = labypos,
label = paste(package, # '\n',
round(prop*100),
'%')),
color = "black",
fill = 'white',
size = rel(3)) +
coord_polar("y", start = 0) +
xlim(0.89, 2.5) +
theme_minimal() +
labs(title = 'Cómo que dplyr!?',
subtitle = 'cantidad de descargas de paquetes tidyverse',
caption = 'datos del 2019-01-01 al 2019-06-30') +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank(),
plot.title = element_text(size=14, face="bold"),
plot.subtitle = element_text(size = 8),
axis.text = element_blank(),
legend.position = 'none')
# Regálame un emoji de piña para saber que lograste crear la gráfica!
# Coméntala de regreso en el tweet --> https://bit.ly/2xzgu9n
# guardamos la gráfica
ggsave('./images/cran.jpeg',
width = 8,
height = 4,
units = 'in')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment