Interactive Data Visualization

Row

Car Failure Analysis

Failure

Car Failures in US

1624

Labour Cost

Georgia

75

Florida

168

California

200

Texas

293

Row

Failure By State

Top States

FM Vs Mileage

Scatter Plot of Month Vs Mileage

Box Plot

Box plot of Top State

Map

Map

Data Table

Pivot Table

Summary Report

Column {data-width = 100}

Max Failure Month

23

Average Labor Cost

242.92

Average Mileage at Failure

20578.67

Column

Report

  • This is a report on 1624 car failures.

  • The average labor cost was USD 242.9180111.

  • The average material cost was USD 179.3948276.

This report was generate on March 26, 2024.

---
title: "Dian's Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(knitr)
library(DT)
library(rpivotTable)
library(ggplot2)
library(plotly)
library(dplyr)
library(openintro)
library(highcharter)
library(readxl)
library(ggvis)

```


```{r}
data <- read_excel("C:/Users/Asus/Downloads/Lab2/dashboard/VehicleFailure.xlsx")
```

```{r}
mycolors <- c("blue","##FFC125","darkgreen","darkorange")
```

Interactive Data Visualization
================================================================================

Row
--------------------------------------------------------------------------------

### Car Failure Analysis
```{r}
valueBox(paste("Failure"),
         color="warning")
```


### Car Failures in US

```{r}
valueBox(length(data$State),
         icon="fa-user")
```

### **Labour Cost**

```{r}
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")))
```

### Georgia
```{r}
valueBox(sum(data$State == "GA"),
         icon = 'fa-building')
```

### Florida
``` {r}
valueBox(sum(data$State == "FL"),
         icon = 'fa-building')
```

### California
```{r}
valueBox(sum(data$State == "CA"),
         icon = 'fa-building')
```

### Texas 
``` {r}
valueBox(sum(data$State == "TX"),
         icon = 'fa-building')
```

Row
--------------------------------------------------------------------------------

### Failure By State

```{r}
p1 <- data %>%
  group_by(State) %>%
  summarise(count = n()) %>%
  plot_ly(x = ~State,
         y = ~count, 
         color = rainbow(51),
         type = 'bar') %>%
layout(xaxis = list(title = "Failure By State"),
yaxis = list(title = 'Count'))
p1
```

### Top States
```{r}
p2 <- data %>%
  group_by(State) %>%
  summarise(count = n()) %>%
  filter(count>50) %>%
  plot_ly(labels = ~State,
         values = ~count, 
         marker = list(colors = mycolors)) %>%
  add_pie(hole = 0.2) %>%
  layout(xaxis = list(zeroline = F,
                      showline = F, 
                      showticklabels = F, 
                      showgrid = F),
         yaxis = list(zeroline = F, 
                      showline = F,
                      showticklabels = F,
                      showgrid = F))
p2
```

### FM Vs Mileage

```{r}
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 of Month Vs Mileage

```{r}
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
```

Box Plot
================================================================================

### Box plot of Top State

```{r}
library(plotly)
library(dplyr)

box_plot <- data %>%
  group_by(State) %>%
  ggplot(aes(x = State, y = lc, fill = State)) +
  geom_boxplot()

interactive_box_plot <- ggplotly(box_plot)

interactive_box_plot

```

Map
================================================================================

### Map
```{r}
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: Vehiclefailure.xlsx") %>%
  hc_add_series_map(usgeojson, car,
                    name = "State",
                    value = "total",
                    joinBy = c("woename", "State")) %>%
  hc_mapNavigation(enables = T)
```

Data Table
================================================================================

```{r}
datatable(data,
          caption = "Failure Data",
          rownames = T,
          filter = "top",
          options = list(pageLength = 25))
```

Pivot Table
================================================================================

```{r}
rpivotTable(data,
            aggregatorName = "Count",
            cols = "fm",
            rows = "State",
            renderName = "Heatmap")
```

Summary Report {data-orientation=columns}
================================================================================

Column {data-width = 100}
--------------------------------------------------------------------------------

### Max Failure Month
```{r}
valueBox(max(data$fm),
         icon = "fa-user")
```

### Average Labor Cost
```{r}
valueBox(round(mean(data$lc),
               digits = 2),
         icon = "fa-area-chart")
```


### Average Mileage at Failure
```{r}
valueBox(round(mean(data$Mileage),
               digits = 2),
         icon = "fa-area-chart")
```

Column
--------------------------------------------------------------------------------

Report

* This is a report on `r length(data$fm)` car failures.

* The average labor cost was USD `r mean(data$lc)`.

* The average material cost was USD `r mean(data$mc)`.

This report was generate on `r format(Sys.Date(), format = "%B %d, %Y")`.