Skip to content

Instantly share code, notes, and snippets.

@juananpe
Created January 16, 2021 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juananpe/7a22dede78c597d67f56d949b60168e0 to your computer and use it in GitHub Desktop.
Save juananpe/7a22dede78c597d67f56d949b60168e0 to your computer and use it in GitHub Desktop.
library(reshape2)
library(ggplot2)
httpsN <- c(760, 1884, 4121)
httpN <- c(597, 1475, 2606)
probintzia <- c("Araba", "Gipuzkoa", "Bizkaia")
df = data.frame(httpsN, httpN, probintzia)
df$https <- df$httpsN / (df$httpsN + df$httpN)
df$http <- df$httpN / (df$httpsN + df$httpN)
df<-df[,3:length(df)]
df.long<-melt(df,id.vars="probintzia")
df.long$numbers <- c(httpsN, httpN)
h <- .5
p <- ggplot(df.long,aes(x=probintzia,y=value,fill=variable))+
geom_bar(stat="identity",position="dodge")+
xlab("httpS vs http")+ylab("") + scale_y_continuous(breaks=seq(0, 1, by = 0.1))
p <- p + geom_hline(yintercept=h, linetype="dashed", color = "red")
p <- p + guides(fill=guide_legend(title="Zerbitzari mota"))
p <- p + geom_text(aes(label=paste0(round(value, 4) * 100, "%")), position=position_dodge(width=0.9), vjust=-0.25)
p <- p + geom_text(aes(label=paste0("(",numbers,")")), position=position_dodge(width=0.9), vjust=1.5)
p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment