Last active
October 8, 2019 09:47
-
-
Save cavedave/5c353e55e5094424386eb9cc5858f544 to your computer and use it in GitHub Desktop.
UK income and tax data. Copy of https://twitter.com/DLeonhardt/status/1180990667700477952 but for the UKData from https://www.gov.uk/government/statistics/percentile-points-from-1-to-99-for-total-income-before-and-after-tax
This file contains 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
library(tidyverse) | |
money <- read.csv("NS_Table_3_1a_1617.csv",skip = 5, header = T, nrows = 100, dec=",") | |
#, nrows = 1, | |
money <- money[-1,] | |
money<-select (money,-c(X,X.1,X.2,X.3,X.4,X.5,X.6,X.7,X.8,X2008.09..a.)) | |
#money<-as.numeric(sub(",", ".", money)) | |
money$Percentile.point <- as.integer(money$Percentile.point) | |
#money <- money[order(money$Percentile.point), ] | |
head(money) | |
#make an id row | |
money <- tibble::rowid_to_column(money, "ID") | |
#now the after tax part of that spreadsheet | |
tax <- read.csv("NS_Table_3_1a_1617.csv",skip = 106, header = F, nrows = 100, dec=",") | |
#, nrows = 1, | |
tax <- tax[-1,] | |
tax<-select (tax,-c(V2,V3,V13)) | |
tax <- tibble::rowid_to_column(tax, "ID") | |
head(tax,20) | |
#Graph raw earnings | |
library(ggplot2) | |
# Basic line plot with points | |
p<-ggplot(data=money, aes(x=X2016.17, y=ID)) +#, group=1 X1999.00 | |
geom_line()+ | |
geom_point() | |
p<-p + ggtitle("UK Earnings 2017") + | |
xlab("Earnings 1000's") + ylab("Percentile") | |
#p<-p + scale_y_discrete(breaks=c(0,10,20,30,40,50,60,70,80,90,100),limits=c("0","10","20","30","40","50","60","70","80","90","100") | |
#p<-p + scale_y_discrete(name="Percentiles", limits=c(0, 100)) | |
p<-p+ theme_bw() | |
p<-p+theme(plot.title = element_text(hjust = 0.5)) | |
ggsave("earnings.png") | |
#Graph raw afeter tax | |
library(ggplot2) | |
# Basic line plot with points | |
p<-ggplot(data=tax, aes(x=V21, y=ID)) +#, group=1 X1999.00 | |
geom_line()+ | |
geom_point() | |
p<-p + ggtitle("UK after tax Earnings 2017") + | |
xlab("Earnings 1000's") + ylab("Percentile") | |
#p<-p + scale_y_discrete(breaks=c(0,10,20,30,40,50,60,70,80,90,100),limits=c("0","10","20","30","40","50","60","70","80","90","100") | |
#p<-p + scale_y_discrete(name="Percentiles", limits=c(0, 100)) | |
p<-p+ theme_bw() | |
p<-p+theme(plot.title = element_text(hjust = 0.5)) | |
ggsave("afterTax.png") | |
#make a new dataframe to do NYT calculations | |
after_tax <- select(money,X2016.17, ID) | |
after_tax["left"] <-tax$V21 | |
after_tax["after"] <-100-(((tax$V21)/money$X2016.17)*100) | |
#Now graph using analysed data | |
p<-ggplot(data=after_tax, aes(y=after, x=ID)) +#, group=1 X1999.00 | |
geom_line()+ | |
geom_point() | |
p<-p + ggtitle("UK Income Tax Rate") + | |
xlab("<- Less income Income Percentile More income ->") + ylab("Percentage Tax") | |
#p<-p + scale_y_discrete(breaks=c(0,10,20,30,40,50,60,70,80,90,100),limits=c("0","10","20","30","40","50","60","70","80","90","100") | |
#p<-p + scale_y_discrete(name="Percentiles", limits=c(0, 100)) | |
p<-p+ theme_bw() | |
p<-p+theme(plot.title = element_text(hjust = 0.5)) | |
#<-p + annotate("text", x = 2:5, y = 0, label = "<- Less income") | |
ggsave("taxrate.png") | |
#comparison not in percentiles | |
p<-ggplot(data=after_tax, aes(y=left, x=X2016.17)) +#, group=1 X1999.00 | |
geom_line()+ | |
geom_point() | |
p<-p + ggtitle("UK Income Before and After Tax") + | |
xlab("Income") + ylab("After Tax") | |
#p<-p + scale_y_discrete(breaks=c(0,10,20,30,40,50,60,70,80,90,100),limits=c("0","10","20","30","40","50","60","70","80","90","100") | |
#p<-p + scale_y_discrete(name="Percentiles", limits=c(0, 100)) | |
p<-p+ theme_bw() | |
p<-p+theme(plot.title = element_text(hjust = 0.5)) | |
#<-p + annotate("text", x = 2:5, y = 0, label = "<- Less income") | |
ggsave("taxEarned.png") |
Author
cavedave
commented
Oct 8, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment