From 0cd0fe53e82a646b6d998673425d454443fb35a0 Mon Sep 17 00:00:00 2001 From: chenc29 Date: Tue, 30 Nov 2021 09:40:53 -0500 Subject: [PATCH] add floor data and adjusted bar plot --- app.R | 3 ++- read_wapData.R | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app.R b/app.R index bea0d359..ae74faa7 100644 --- a/app.R +++ b/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") diff --git a/read_wapData.R b/read_wapData.R index 7cd0451b..8e9d64e2 100644 --- a/read_wapData.R +++ b/read_wapData.R @@ -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,18 +324,27 @@ 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(), @@ -342,7 +352,8 @@ make_plot <- function(dat, time_now, building_select, hits_per_wap_semester_by_b 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") \ No newline at end of file