-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtlas.shiny.bits.R
executable file
·184 lines (131 loc) · 5.37 KB
/
Atlas.shiny.bits.R
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#
# This is the user-interface definition of a Shiny web application. You can
# run the application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
##install rgdl & Leaflet library for polygons
# install.packages("rgdal")
library(rgdal)
# install.packages("leaflet")
library(leaflet)
# install.packages("dplyr")
library(dplyr)
# install.packages("colorRamps")
library(colorRamps)
# install.packages("graphics")
library(graphics)
# install.packages("RColorBrewer")
library(RColorBrewer)
# install.packages("foreign")
library(foreign)
library(colorspace)
mydata <- read.dta("c:/mydata.dta")
##load shape file
SLA <- readOGR(dsn= "C:/Users/robertj9/RDirectory/Catlas1.27jan16/Qld.shape files",
layer = "SLA_QLD_06", verbose = FALSE)
##laod SIR data
mydata <- read.dta(file.choose())
##add attribute to shape file
SLA$new.att <- 1:nrow(SLA)
#create dataframe of SLA - was not necessary to create data frame for this project. Leaflet requires a shape file.
data.frame(SLA)
data.frame(SLA)
SLA.df <- as(SLA, "data.frame")
#load file with estimates
data <- read.csv(file.choose())
#create variable of sir values
sir.value <- (select(data, SIR))
#add SIR values to data.frame?
SLA$sir <- sir.value
#create character vector from est.SIR
mutate(data, RISk = ifelse(est.SIR %in% 0.0:0.69, "Very Low",
ifelse(est.SIR %in% 0.7:0.89,
ifelse(est.SIR %in% 0.9:1.09, "Average",
ifelse(est.SIR %in% 1.1:1.29, "High",
ifelse(est.SIR %in% 1.3:2.06, "Very High", "Very High"))))))
ata %>%
mutate(Risk = ifelse(est.SIR < 0.7,
yes = "Very Low",
no = ifelse(est.SIR < 0.9,
yes = "Low",
no = ifelse(est.SIR < 1.1,
yes = "Average",
no = ifelse(est.SIR <1.3,
yes = "High",
no = ifelse(est.SIR >1.31,
yes = "Very High",
no = "na"))))))
##__- trying to fix this mutate function
SLA.df <- as.data.frame(SLA)
SLA.df <- fortify(SLA)
ata <- SLA.df %>%
mutate(Risk = ifelse(estimate < 0.7,
yes = "Very Low",
no = ifelse(estimate < 0.9,
yes = "Very Low",
no = ifelse(estimate < 0.9,
yes = "Low",
no = ifelse(estimate < 1.1,
yes = "Average",
no = ifelse(estimate <1.3,
yes = "High",
no = ifelse(estimate >1.31,
yes = "Very High",
no = "na")))))))
SLA$Risk.label <- ata$Risk
#_____This was actually not necessary, I defined the colours through the bins within the palette .. didn't need this extra label at all.
ata <- SLA %>%
mutate(Risk = ifelse(estimate < 0.7,
yes = "Very Low",
no = ifelse(estimate < 0.9,
yes = "Low",
no = ifelse(estimate < 1.1,
yes = "Average",
no = ifelse(estimate <1.3,
yes = "High",
no = ifelse(estimate >1.31,
yes = "Very High",
no = "Very High"))))))
#_______
#create a colour palette _______________________________________
pal1 <- colorBin( c("#CCCC00","#FFFFFF", "#993399"), SLA$SIR, bins = c( 0.0, 0.7, 0.8, 0.9, 1.1, 1.2, 1.3, 2.06), pretty = FALSE)
pal2 <- colorRamps::blue2yellow(5)
pal3 <- colorNumeric( palette = c("#E5E600", "#FFFFFF", "#660066" ), domain = SLA$SIR, 5)
pal4 <- choose_palette()
pal5 <- diverge_hcl(5, h = c(260, 0), c = 80, l = c(30, 90), power = 1.5,
fixup = TRUE, gamma = NULL, alpha = 1)
pal6 <- colorQuantile("Blues", SLA$SIR, n=5)
pal7 <- colorFactor(c("#993399","#FFFFFF", "#CCCC00"), domain = SLA$Risk.label, ordered =TRUE, na.color = "#808080", alpha = FALSE)
legend.lab <- c("Very High"," ", "High"," ", "Average", " ", "Low", " ", "Very Low")
#_____________________
#draw map
leaflet(SLA) %>%
addPolygons(
stroke = FALSE, fillOpacity = 1, smoothFactor = 0.2,
color = ~pal1(SLA$SIR)
) %>%
addLegend("bottomleft", values = SLA$SIR, title = "Lung Cancer Risk", colors= c( "#993399", "#B970B6", "#D6A9D3", "#F2E2F0", "#FFFFFF","#FBF7E1", "#EFE8A4", "#E0DA66", "#CCCC00" ), labels = legend.lab, opacity = 1)
#__________________________________________
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
))