Can I have some help on how to insert a ranking of top 5 and bottom 5 Subvertical per Vertical? Thank you
vertical is the element and subvertical is the subelement.
Should produce an additional column after total "total" for the ranking of AHT's. Like this:
Data Processing for Subvertical
data_process.subvertical <- data_process %>% select(DATE, Vertical, Subvertical, AHT, total) %>%
dplyr::group_by(DATE, Vertical, Subvertical) %>%
dplyr::summarise(AHT = mean(AHT, na.rm = T), total = sum(total)) %>%
dplyr::ungroup()
View(test_data)
Subvertical AHT
v <- ("Adult") ##change vertical here
subvert.aht <- function(Vertical) {
if (Vertical == v) {
filter1 <- data_process.subvertical %>%
dplyr::filter(Vertical == v)
line_chart_cs <- ggplot2::ggplot(filter1, aes(x = DATE, y = AHT, colour = Subvertical)) +
ggplot2::geom_line() +
scale_x_date(breaks = filter1$DATE) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_line(colour = "black"),legend.position = "bottom" ) +
ggtitle(paste("Monthly AHT -", v, "by Subvertical"))
line_chart_cs
}
else {
print("TEST.")
}
}
subvert.aht(v)