Last active
November 14, 2017 14:17
-
-
Save onstatus/0797face1dca589b0282f22261aba046 to your computer and use it in GitHub Desktop.
R code to generate percentage of BJ DNS traffic using Google PDNS (8.8.8.8)
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
# Get data from ApNic | |
# https://stats.labs.apnic.net/ecdsa/BJ | |
# For instance | |
cat bj_gpdns.csv | |
ISP,Sample,GPDNS % | |
CanalBox-Benin-AS,1299,61.12 | |
SUD-TELCOM-AS,186,34.41 | |
BENINTELECOM,35118,92.57 | |
Spacetel,60193,70.54 | |
JENY-SAS-AS,3091,55.71 | |
OTI-AS,3046,19.21 | |
ISOCEL,13149,15.27 | |
ETISALAT-AS,31734,44.57 | |
UNIVERCELL-AS,1977,1.67 | |
# Get dataframe | |
pdns <- read.csv('bj_gpdns.csv', header=TRUE) | |
#Create new column to store number of sample data going to GPDNS per ISP | |
pdns$Sample_GPDNS <- (pdns$Sample * pdns$GPDNS) / 100 | |
#Compute global percentage of sample data going to GPDNS per ISP | |
pdns$Global_GPDNS <- (pdns$Sample_GPDNS / sum(pdns$Sample) )* 100 | |
#Get percentage of sample data going to GPDNS | |
sum(pdns$Sample_GPDNS) / sum(pdns$Sample) * 100 | |
[1] 62.96601 | |
#Get per ISP, percentage of sample going to GPDNS | |
(pdns$Sample_GPDNS / sum(pdns$Sample) )* 100 | |
[1] 0.53003064 0.04272736 21.70243776 28.34587878 1.14958383 0.39063014 1.34041798 9.44225952 | |
[9] 0.02204102 | |
#Verify that wa have the same percentage | |
(sum(pdns$Sample_GPDNS) / sum(pdns$Sample) * 100) == sum((pdns$Sample_GPDNS / sum(pdns$Sample) )* 100) | |
#Plot | |
#ggplot(pdns, aes(x = ISP, y = Global_GPDNS)) + ylab("% to GPDN") + geom_col(aes(x = ISP, fill = factor(ISP))) | |
#ggplot(pdns, aes(x=ISP,y=Global_GPDNS,fill=ISP)) + geom_col() + ylab("% to GPDN") | |
#ggplot(pdns, aes(x=ISP,y=Global_GPDNS,fill=ISP)) + geom_col() + ylab("% to GPDN") + guides(fill=FALSE) | |
#ggplot(pdns, aes(x=ISP,y=Global_GPDNS,fill=ISP)) + geom_bar(stat="identity") + ylab("% to GPDN") + guides(fill=FALSE) | |
ggplot(pdns, aes(x=reorder(ISP, -Global_GPDNS),y=Global_GPDNS,fill=ISP)) + geom_bar(stat="identity") + ylab("% to GPDN") + guides(fill=FALSE) + xlab("ISPs") | |
#ggplot(pdns, aes(x=reorder(ISP, -Global_GPDNS),y=Global_GPDNS,fill=ISP, label=Global_GPDNS)) + geom_col() + ylab("% to GPDNS") + guides(fill=FALSE) + xlab("ISPs") + theme() + geom_text(vjust=-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment