Last active
March 24, 2018 18:46
-
-
Save amirmasoudabdol/85602af4e2c304a9202f57a47141d629 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code will reproduce the production-ready plot reperested in following blogpost, https://panic.com/blog/mystery-of-the-slow-downloads/ | |
# There might be some slight misplacements due to the font spacing, I've used Nitti Grotesk. | |
library(tidyverse) | |
library(lubridate) | |
library(ggthemes) | |
library(showtext) | |
# font_add("Nitti Grotesk", "Typefaces/Nitti Grotesk/NittiGrotesk-Normal.otf") | |
# font_add("Nitti Grotesk Bold", "Typefaces/Nitti Grotesk/NittiGrotesk-Bold.otf") | |
# showtext_auto() | |
df1 = read_csv("part1.log.csv", col_names = FALSE) | |
names(df1) = c('TS', 'Speed', 'TLD', 'Location') | |
df1 <- df1 %>% mutate(TS = mdy_hms(TS)) | |
df1 <- df1 %>% | |
filter(TS < as_date('2017-11-22') & TS > as_date('2017-11-20')) %>% | |
filter(Speed < 20000) | |
dff <- df1 %>% | |
group_by(TLD) %>% | |
summarise(count = n(), mean = mean(Speed)) %>% | |
filter(count >= 10) %>% | |
arrange(mean) | |
selectedProviders <- factor(c('comcast.net', 'cox.net', 'charter.com', 'rr.com', 'verizon.net', 'shawcable.net', | |
'virginm.net', 'qwest.net', 'btcentralplus.com', | |
't-ipconnect.de', 'sbcglobal.net')) | |
dft <- df1 %>% | |
filter(TLD %in% selectedProviders & Speed < 250000.) | |
dft$TLD <- factor(dft$TLD, levels = rev(selectedProviders)) | |
plotOrange <- "#fecb57" | |
textOrange <- "#fca05c" | |
blue <- "#41b9d1" | |
red <- "#fc4349" | |
size <- length(selectedProviders) - 1 | |
linodeColors <- c(textOrange, rep(blue, size)) | |
comcastColors <- c(red, rep(blue, size)) | |
x_axis_title_face <- c('bold', rep('plain', size)) | |
# x_axis_title_family <- c('Nitti Grotesk Bold', rep('Nitti Grotesk', size)) | |
comcastPlot <- ggplot() + | |
theme_minimal() + | |
# theme(text = element_text(family = "Nitti Grotesk")) + | |
labs( | |
title = "Connection to Panic via Cogent") + | |
ylab("Speed bold(kB/s)") + | |
theme( | |
# plot.title = element_text(family = "Nitti Grotesk Bold", size = 18, hjust = .4), | |
axis.title.y = element_blank() | |
) + | |
theme( | |
axis.text.x = element_text(size = 12), | |
axis.text.y = element_text(size = 16, | |
color = rev(linodeColors), | |
family = rev(x_axis_title_family), | |
face = rev(x_axis_title_face)) | |
) + | |
theme( | |
panel.grid.minor.x = element_blank(), | |
panel.grid.major.x = element_blank(), | |
panel.border = element_blank() | |
) + | |
theme( | |
axis.ticks.x = element_line(color="gray", size=.75), | |
axis.ticks.length = unit(0.2, "cm"), | |
axis.line.x = element_line(color = "gray", size = .5), | |
axis.text.x = element_text(margin = margin(5, 5, 15, 5, "pt")) | |
) + | |
scale_y_continuous(breaks = seq(0, 20000, 5000), | |
limits = c(0, 20500), | |
expand = c(.005, 0) | |
) + | |
scale_x_discrete(expand = c(0, 1.2)) + | |
stat_boxplot(data = dft, aes(x = TLD, y = Speed), geom = "errorbar", | |
width = 0.2, | |
color = "black") + | |
geom_boxplot(data = dft, aes(x = TLD, y = Speed), | |
position = "dodge", | |
width = 0.6, | |
color = rev(comcastColors), | |
fill = rev(comcastColors), | |
lwd = 0.05, fatten = 15, | |
outlier.size = 1.75, outlier.alpha = .5, outlier.stroke = .0, | |
show.legend = FALSE) + | |
annotate(geom = 'text', x = 11.8, y = 1000, label = 'bold("356.3 kB/s")', | |
color = textOrange, | |
parse = TRUE, | |
# size = 5, family = "Nitti Grotesk Bold" | |
) + | |
coord_flip() | |
comcastStats <- ggplot_build(comcastPlot)$data[[1]] | |
comcastPlot <- comcastPlot + | |
geom_segment(data = comcastStats, | |
aes(x = xmin-.20, xend = xmax+.20, y = middle, yend = middle), | |
color = "black", size = .7) | |
comcastPlot | |
# ggsave("comcast.pdf", width = 12, height = 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment