# Load the data
data <- read.csv("C:/Users/Dell/Desktop/vehicle.csv")

Define colors for visualizations

mycolors <- c("blue", "darkgreen", "darkorange", "yellow")

Iterative data visualization

Define inline CSS to adjust value box size

Car Failure Analysis

valueBox(paste("Failure"), color = "warning")
Failure

Car Failure in US

valueBox(length(data$State),
         icon = "fa-user")
1624

Labour Cost

gauge(round(mean(data$lc), digits = 2), min = 0, max = 350, 
      gaugeSectors(success = c(0, 150), warning = c(150, 240), danger = c(240, 350), 
                   colors = c('green', 'yellow', 'red')))

Massachusetts

valueBox(sum(data$State == "MA"), icon = 'fa-building')
21

California

valueBox(sum(data$State == 'CA'), icon = 'fa-building')
200

Texas

valueBox(sum(data$State == "Tx"), icon = 'fa-building')
0

Florida

valueBox(sum(data$State == "FL"), icon = 'fa-building')
168

Failures By State

p1<-data %>%
  group_by(State)%>%
  summarise(count=n())%>%
  plot_ly(x=~State,
          y=~count,
          color="blue",
          type='bar')%>%
layout(xaxis=list(title="Failures By State"),
yaxis=list(title='Count'))
p1
p3<-plot_ly(data,
            x=~fm,
            y=~Mileage,
            text=paste("FM:",data$fm,
                       "Mileage:",
                       data$Mileage),
            type="bar")%>%
  layout(xaxis=list(title="FM"),
         yaxis=list(title="Failure Mileage"))
p3

Scatter plot

p4<-plot_ly(data,x=~fm)%>%
  add_markers(y=~Mileage,
              text=~paste("Mileage: ",Mileage),
              showlegend=F)%>%
              add_lines(y=~fitted(loess(Mileage~fm)),
              name="Loess Smoother",
              color=I("#FFC125"),
              showlegend=T,
              line=list(width=5))%>%
                layout(xaxis=list(title="Month"),
              yaxis=list(title="Mileage"))
p4
top_state <- data %>%
  group_by(State) %>%
  summarise(count = n()) %>%
  arrange(desc(count)) %>%
  slice(1) %>%
  pull(State)

# Filter data for the top state
top_state_data <- data %>%
  filter(State == top_state)

# Create box plot for the top state
p5 <- plot_ly(top_state_data, 
              x = ~State, 
              y = ~Mileage,
              type = "box") %>%
  layout(xaxis = list(title = "Top State"),
         yaxis = list(title = "Mileage"))

p5
car<-data %>%
  group_by(State) %>%
  summarize(total=n())
car$State<-abbr2state(car$State)

highchart()%>%
  hc_title(text="Car Failures in US")%>%
  hc_subtitle(text="Source: vehicle.csv")%>%
  hc_add_series_map(usgeojson,car,name=" State",
                    value="total",
                    joinBy=c("woename","State")) %>%
  hc_mapNavigation(enabled=T)