Skip to content
Permalink
Browse files
add floor data and adjusted bar plot
  • Loading branch information
chenc29 committed Nov 30, 2021
1 parent 0a97d46 commit 0cd0fe53e82a646b6d998673425d454443fb35a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
3 app.R
@@ -260,7 +260,8 @@ server <- function(input, output, session) {
# "google-maps" style plot
output$hourly_crowd <- renderPlot({
# get data to feed into make_plot
data <- user_predictions %>% filter(weekday == application_state$day & Building == application_state$building)
data <- user_predictions_fl %>% filter(weekday == application_state$day & Building == application_state$building)
# browser()
make_plot(data, application_state$time, application_state$building, hits_per_wap_semester_by_building_max)
}, bg="transparent")

@@ -50,7 +50,7 @@ rpi_wap_stats <- readRDS("../COVID_RPI_WiFi_Data/rpi_wifi_semester_day_summary.r
#buildinginfo <- readRDS("../COVID_RPI_WiFi_Data/buildinginfo.rds")

#user_prediction: Building, weekday, Hour, users, Mean_Usercount, latitude, longitude, buildingType
user_predictions <- readRDS("../COVID_RPI_WiFi_Data/median_last3wks_with_floors.rds")
user_predictions_fl <- readRDS("../COVID_RPI_WiFi_Data/median_last3wks_with_floors.rds")

################################################################################################################
###CLEANING DATA
@@ -81,11 +81,12 @@ hits_per_wap_semester_by_building_max <- hits_per_wap_semester_by_building_max %
hits_per_wap_semester_by_building_max <- hits_per_wap_semester_by_building_max %>% group_by(Building) %>% summarise_all(funs(max)) %>% ungroup() %>% select(Building, usercount_max)
colnames(hits_per_wap_semester_by_building_max) <- c('Building', 'capacity')

user_predictions <- user_predictions %>%
user_predictions <- user_predictions_fl %>%
dplyr::group_by(Building, Weekday, Hour, lat, lng, BuildingType) %>%
dplyr::summarize(totalusers = sum(users)) %>%
ungroup()

names(user_predictions_fl)[names(user_predictions_fl) == 'Weekday'] <- 'weekday'
names(user_predictions)[names(user_predictions) == 'Weekday'] <- 'weekday'
names(user_predictions)[names(user_predictions) == 'totalusers'] <- 'users'

@@ -323,26 +324,36 @@ capacity_intercept <- function(capacity){
cut <- c(c1, c2, c3, capacity)
}

cbPalette <- c("#8dd3c7", "#ffffb3", "#bebada", "#fb8072", "#80b1d3", "#fdb462", "#b3de69", "#fccde5", "#d9d9d9", "#bc80bd")

# Function to make bar plot
make_plot <- function(dat, time_now, building_select, hits_per_wap_semester_by_building_max){
building_select_cap <- subset(hits_per_wap_semester_by_building_max, hits_per_wap_semester_by_building_max$Building == building_select)
cap_line <- capacity_intercept(building_select_cap$capacity)
ggplot(dat, aes(x=factor(Hour), y=users, fill=(Hour==time_now))) +
geom_bar(stat="identity") +
scale_fill_manual(values=c("skyblue3","mediumvioletred")) +
geom_vline(xintercept = as.integer(time_now)+1, linetype = "dotted") +
dat$Floor <- factor(dat$Floor)
ggplot(dat, aes(x=factor(Hour), y=users, fill=forcats::fct_rev(Floor))) +
# ggplot(dat, aes(x=factor(Hour), y=users, fill=(Hour==time_now))) +
geom_rect(alpha.f=0.1, xmin=as.integer(time_now)+.5, xmax=as.integer(time_now)+1.5, ymin=-Inf, ymax=Inf, fill="#c8f7c8") +
geom_bar(stat="identity", color = "black") +
# scale_fill_manual(values=cbPalette) +
scale_fill_manual(values = c("0"="#8dd3c7", "1"="#ffffb3", "2"="#bebada", "3"="#fb8072", "4"="#80b1d3", "5"="fdb462",
"6"="#b3de69", "7"="fccde5", "8"="#d9d9d9", "9"="#bc80bd")) +
# scale_fill_manual(values=c("skyblue3","mediumvioletred")) +
# geom_vline(xintercept = as.integer(time_now)+1, linetype = "dotted") +
geom_hline(yintercept = cap_line, linetype = "dotted") +
scale_x_discrete(labels= Time_AMPM) +
scale_y_continuous(breaks = cap_line, labels = c("25%", "50%", "75%", "100%")) +
ylab("Building Capacity") +
labs(fill = "Floor") +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
plot.background = element_blank(),
axis.ticks.y = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x=element_blank(),
legend.position="none")
legend.position="bottom",
legend.background = element_blank())
}

icon <- awesomeIcons(icon = 'ios-close', iconColor="black", library='ion', markerColor="green")

0 comments on commit 0cd0fe5

Please sign in to comment.