-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate Treemaps with DATA Act Datasets.R
More file actions
105 lines (67 loc) · 3.69 KB
/
Create Treemaps with DATA Act Datasets.R
File metadata and controls
105 lines (67 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#rm(list=ls())
################
# Set up
################
# Install Packages - UNCOMMENT AND RUN THESE COMMANDS IF THE PACKAGES BELOW ARE NOT ALREADY INSTALLED
# install.packages("tidyr")
# install.packages("plyr")
# install.packages("dplyr")
# install.packages("treemap")
# Attach the packages to be used in the script
library(tidyr)
library(plyr)
library(dplyr)
library(treemap)
###################
# Step 1: Load Data
###################
# Set the working directory to the file location on your computer
# example: using Documents on the C drive
setwd("C:\\Users\\Public\\Documents\\")
# check the directory was set correctly
getwd()
# Import dataset
tas_categories <- read.csv("tas_categories.csv")
names(tas_categories)
table(tas_categories$treasury_account.reporting_agency_name)
# Subset Data To Include Only EPA Data'
table(tas_categories$treasury_account.reporting_agency_name=="Department of Transportation" & tas_categories$treasury_account.reporting_agency_id=="69")
dot_data <- tas_categories[which(tas_categories$treasury_account.reporting_agency_id=="69"),]
# Drop unneeded dataset
rm(tas_categories)
# Create Summary Tables of Spending by Object Class
gross_majorobjectclass <- data.frame(aggregate(dot_data$gross_outlay_amount_by_program_object_class_cpe,
by=list(dot_data$object_class.major_object_class_name), FUN=sum))
# Create Treemap of EPA Spending by Major Object Class (Saved as PNG File)
png(file="DOT_Spending_by_Object_Class.png")
treemap(gross_majorobjectclass,
index = c("Group.1"),
vSize = "x",
vColor = "Group.1",
type = "index",
palette = c("#0086c8", "#2869a4", "#143e64", "#2c2c2c", "#00caec", "#007faa"),
title="DOT Gross Spending by Major Object Class",
fontsize.title = 14)
dev.off()
# Create Summary Table of DOT Spending by Secondary Object Class
# Major Object Class: Other generates a blank Secondary Object Class, Replace Values
dot_data$object_class.object_class_name <- as.character(dot_data$object_class.object_class_name)
dot_data$object_class.object_class_name[which(dot_data$object_class.major_object_class_name=="Other" &
dot_data$object_class.object_class_name=="")] <- "Other"
dot_data$gross_outlay_absolute_val_cpe <- abs(dot_data$gross_outlay_amount_by_program_object_class_cpe)
gross_objectclass <- data.frame(aggregate(dot_data$gross_outlay_absolute_val_cpe,
by=list(dot_data$object_class.object_class_name), FUN=sum))
# Create Treemap of DOT Spending by Secondary Object Class
png(file="DOT_Spending_by_Secondary_Object_Class.png")
treemap(gross_objectclass,
index = c("Group.1"),
vSize = "x",
vColor = "Group.1",
type="index",
palette = c("#0086c8", "#2869a4", "#143e64", "#00caec", "#007faa",
"#00b5db", "#aae1f4", "#e7f7f9", "#f4f4f4", "#2c2c2c",
"#414b57", "#6e747e", "#bcbec2", "#dedfe0",
"#024558", "#416878", "#6b8a97", "#b5cdd4", "#d8edf2"),
title = "DOT Spending by Secondary Object Class - Absolute Values",
fontsize.title = 14)
dev.off()