I am new here and need some help! I am working on a shiny app for a class project and I am almost done with one of my tabs. I need help with sorting my bars. My bars are not in order by month, what I mean is February should come after January but its the inverse in my graph. I have been looking all over and haven't found a solution that didn't throw and error...so I created an account hoping someone could point me in the right direction.
Here is the link to the dataset: https://www.kaggle.com/jessemostipak/hotel-booking-demand
Here is my code and image of my shiny app working
#install packages
library(shiny)
library(shinythemes)
library(ggplot2)
library(dplyr)
#loading data
hotel_df <- read.csv("/Users/chrismcmanus/Documents/DSBA 5122 - Visual Analytics/ShinyApp/Data/Spreadsheet for ShinyApp.csv")
#list of hotels
hotel_list <- list("Resort Hotel","City Hotel")
#converting to long data
dfm <- melt(hotel_df, id.vars=c("stays_in_weekend_nights", "stays_in_week_nights", "hotel", "arrival_date_month"))
#creating UI layout
ui <- fluidPage(theme=shinytheme("cyborg"),
titlePanel("Hotel popularity based on count of stays"),
sidebarLayout(
sidebarPanel(
selectInput(inputId="hotel_2", label="Select the Hotel", choices=hotel_list)),
mainPanel(
tabsetPanel(
tabPanel("Weekend Nights", plotOutput("plot")),
tabPanel("Week Nights", plotOutput("plot_2"))
))))
#creating server
server <- function(input, output, session) {
htl_type <- reactive({filter(dfm, hotel==input$hotel_2)})
output$plot <- renderPlot({
ggplot(htl_type(), aes(x=stays_in_weekend_nights, y=arrival_date_month)) +
geom_bar(stat="identity", position="dodge") + labs(x="Count of stays during Weekend", y="Check-in Month") +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) + coord_flip()
})
output$plot_2 <- renderPlot({
ggplot(htl_type(), aes(x=stays_in_week_nights, y=arrival_date_month)) +
geom_bar(stat="identity", position="dodge") + labs(x="Count of stays during Week", y="Check-in Month") +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) + coord_flip()
})
}
#displaying shiny app
shinyApp(ui, server)
Any help would be greatly appreciated!