-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar_theft_dashboard.R
51 lines (45 loc) · 1.69 KB
/
Car_theft_dashboard.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
library(shiny)
library(ggplot2)
# Load the dataset
data <- read.csv(file.choose())
# Define UI
ui <- fluidPage(
titlePanel("Vehicle Theft Dashboard"),
sidebarLayout(
sidebarPanel(
selectInput("state", "Select State:", choices = unique(data$State)),
sliderInput("year_range", "Select Year Range:",
min = min(data$Model.Year), max = max(data$Model.Year),
value = c(min(data$Model.Year), max(data$Model.Year)), step = 1)
),
mainPanel(
plotOutput("theft_plot"),
plotOutput("rank_plot")
)
)
)
# Define server logic
server <- function(input, output) {
output$theft_plot <- renderPlot({
filtered_data <- data[data$State == input$state &
data$Model.Year >= input$year_range[1] &
data$Model.Year <= input$year_range[2], ]
ggplot(filtered_data, aes(x = Model, y = Thefts, fill = Model)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(title = paste("Vehicle Theft in", input$state),
x = "Vehicle Model", y = "Thefts")
})
output$rank_plot <- renderPlot({
filtered_data <- data[data$State == input$state &
data$Model.Year >= input$year_range[1] &
data$Model.Year <= input$year_range[2], ]
ggplot(filtered_data, aes(x = Model.Year, y = Rank, group = Model, color = Model)) +
geom_line() +
geom_point() +
labs(title = paste("Rank of Vehicle Models in", input$state),
x = "Model Year", y = "Rank")
})
}
# Run the application
shinyApp(ui = ui, server = server)