Interactive Data Visualization

Row

Total number of observation

7702

Gender split

Average insured declared Value of cars

385617

Total Number of Claims

1877

Total profit

19336691

Row

Statewise Total settled claim

Profitable car models

Row

Year on Year Settled Claim Vs profit

Cubic capacity based Premium Vs Profit

Data Table

Pivot Table

---
title: "Vaibhav: Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    social: [ "twitter", "facebook", "menu"]
    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(ggvis)
```


```{r}
datas <- read.csv("car.csv")
```

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

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

Row
-------------------------------------
### Total number of observation

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

### Gender split

```{r}
h5=datas %>% 
  group_by(`Gender`) %>% 
  summarise(count=n())

p5=plot_ly(h5) %>% 
  add_pie(labels=h5$`Gender`,values=h5$count,hole=0.5)
p5
```

### Average insured declared Value of cars

```{r}
valueBox(round(mean(datas$IDV), digits = 0),
         icon = 'fa-money')
```

### Total Number of Claims

```{r}
valueBox(sum(datas$ClaimsInd),
         icon = 'fa-thumbs-up')
```



### Total profit 

```{r}
valueBox(round(sum(datas$profit), digits = 0),
         icon = 'fa-money')
```

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

### Statewise Total settled claim


```{r}
car <- datas %>%
         group_by(State) %>%
         summarize(total_claim = sum(Claim.Amount))

p4=plot_ly(car) %>% 
  add_pie(labels=car$State,values=car$total_claim,hole=0.5)
p4
```

### Profitable car models

```{r}
model <- datas %>%
  group_by(Mfr.Model) %>%
  summarize(average_claim = mean(Claim.Amount), average_profit=mean(profit), counts=n())%>%
  arrange(desc(average_claim))
colors <- c('#4AC6B7', '#1972A4', '#965F8A', '#FF7070', '#C61951')
fig <- plot_ly(model, y = ~average_profit, x = ~average_claim, color = ~Mfr.Model, size = ~counts/1000, colors = colors,
               type = 'scatter', mode = 'markers',
               marker = list(symbol = 'circle', sizemode = 'diameter',
                             line = list(width = 2, color = '#FFFFFF')),
               text = ~paste('Car model:', Mfr.Model, '
Average Claim amount:',average_claim,'
Average Profit:', average_profit, '
Total Number of claims:', counts)) %>% layout(title = 'Average Claim Amount v. Average Profit, by Car models', yaxis = list(title = 'Average claim in Rs'), xaxis = list(title = 'Average profit in Rs')) fig ``` Row ------------------------------------ ### Year on Year Settled Claim Vs profit ```{r} year <- datas %>% group_by(Year) %>% summarize(total_claim = sum(Claim.Amount), profit=sum(profit)) p5 <- plot_ly(year, x=~Year) %>% add_bars(y = ~total_claim, text = ~paste("total_claim: ", total_claim), showlegend = F) %>% add_lines(y = ~fitted(loess(profit ~ Year)), name = "Total Profit", color = I("#FFC125"), showlegend = F, line = list(width=5)) %>% layout(xaxis = list(title = "Year"), yaxis = list(title = "Money")) p5 ``` ### Cubic capacity based Premium Vs Profit ```{r} capacity<- datas %>% group_by(Cubic.Capacity)%>% summarise(average_premium= mean(Premium), profit= mean(profit)) p6 <- plot_ly(capacity, x=~Cubic.Capacity) %>% add_bars(y = ~average_premium, text = ~paste("Average premium: ", average_premium), showlegend = F) %>% add_lines(y = ~fitted(loess(profit ~ Cubic.Capacity)), name = "Total Profit", color = I("#FFC125"), showlegend = F, line = list(width=5)) %>% layout(xaxis = list(title = "Cubic Capacity"), yaxis = list(title = "Average Profit")) p6 ``` Data Table ======================================== ```{r} datatable(datas, caption = "Insurance", rownames = T, filter = "top", options = list(pageLength = 25)) ``` Pivot Table ========================================= ```{r} rpivotTable(datas, aggregatorName = "Year", cols= "Year", rows = "Mfr.Model", rendererName = "Heatmap") ```