Noi Kogman 207653312 Lina Golan 31368980

##Q2 The second data you have been given is titanic.csv, and it presents descriptions of different passengers on the Titanic and whether 1.

Interactive Data Visualization

Row

Row

Explanations

Graph1

Graph1 - This graph is a scatter plot that displays the relationship between two variables: the age and fare of passengers on the Titanic. Each point on the plot represents a single passenger, and the position of the point corresponds to the age and fare of that passenger. The color of each point represents the survival status of the passenger, with blue indicating that the passenger did not survive and pink indicating that the passenger did survive. The legend on the graph provides a key to the color scheme. There appears to be a cluster of blue markers in the lower-left corner of the graph, which suggests that many of the passengers who did not survive were younger and paid a lower fare. The pink markers are more spread out across the graph, which suggests that passengers who survived were of varying ages and paid varying fares. The majority of passengers on the Titanic paid fares of $100 or less, as indicated by the concentration of markers along the left side of the graph. There are a few outliers in the data, such as the passenger who paid the highest fare (marked by a pink marker), and the older passenger who paid a very low fare (marked by a blue marker). The graph provides a visual representation of the correlation between age and fare. While there is no clear trend line or strong correlation between these variables, it is evident that there were passengers of all ages who paid a wide range of fares.

Graph2

Graph2 - The graph shows the survival rate of passengers by passenger class on the Titanic. The x-axis represents the passenger class (1st, 2nd, and 3rd), and the y-axis represents the percentage of passengers who survived. The bars are colored based on the survival outcome: grey for passengers who did not survive and pink for passengers who survived. From the graph, we can see that the survival rate is highest for passengers in the first class, followed by the second class, and then the third class. This suggests that passenger class was a significant factor in determining survival rates on the Titanic. Overall, the graph provides insight into the relationship between passenger class and survival rates on the Titanic and highlights the importance of socio-economic factors in determining survival outcomes during disasters.

Graph3

Graph3 - The pie chart shows the survival rates of passengers aboard the Titanic. The chart is divided into two sections: “Survived” and “Not Survived”, each represented by a slice of the pie. The size of each slice corresponds to the percentage of passengers in that category. From the chart, we can see that roughly 42% of passengers survived the disaster, while the remaining 58% did not. This highlights the severity of the disaster and the relatively low survival rates. The chart is also color-coded using a custom color palette with shades of light blue and deep pink. The legend shows which color corresponds to each section of the chart. The chart is interactive, so you can hover over each slice to see the exact percentage and count of passengers in that category. Overall, the pie chart provides a quick and visually appealing way to understand the survival rates of passengers aboard the Titanic.

Graph4

Graph4 - The box plot shows the distribution of the fares paid by passengers in each passenger class (1st, 2nd, and 3rd). We can see that the fares for 1st class passengers had a much wider range than the fares for 2nd and 3rd class passengers. The median fare for 1st class was also much higher than the median fares for 2nd and 3rd class. There were some outliers in all three passenger classes, but they were more numerous and farther from the median in 1st class. Overall, this plot shows how the fares paid by passengers varied depending on their passenger class, with 1st class passengers paying much higher fares on average than 2nd and 3rd class passengers.

Relationship in all the dash

Relationship in all the dash - It can be seen that the graphs in the dashboard complement each other in order to provide a complete picture of the data. We first used simple relative graphs to get a general and broader understanding of the data. Then, we created complex plots that use more features to analyze the data at a finer resolution. In our opinion, the connections between the plots in the dashboard enhance the user’s understanding.

---
title: "Titanic dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: ["twitter", "facebook"]
    source_code: embed
date: "2023-05-10"
---
Noi Kogman 207653312
Lina Golan 31368980

##Q2 
The second data you have been given is `titanic.csv,` and it presents descriptions of different passengers on the Titanic and whether 1.

- build a dashboard that contains four interactive graphs. Explain the graphs and the relationship in all the dash.

```{r setup, include=FALSE}
library(plotly)
library(data.table)
library(ggplot2)
library(dplyr)
library(plotly)
```


```{r}
data <- data.table(read.csv("titanic.csv"))
```

Interactive Data Visualization
=================================
Row
-------------------------------------

```{r}
data[, .(count = .N), by = Survived][, Survival := ifelse(Survived == 1, "Survived", "Not Survived")] %>%  plot_ly(labels = ~Survival, values = ~count, type = "pie", textposition = "inside", marker = list(colors = ~c("#008080", "#FFD1DC"))) %>% layout(title = "Survival Rates", showlegend = T)

```

```{r}
data[, .(count = .N), by = .(Pclass, Survived)][, 
  percentage := round(count / sum(count)*100,3), by = Pclass] %>% 
  plot_ly(x = ~Pclass, y = ~percentage, 
          color = ~factor(Survived), 
          colors = c("#800020", "#FFD1DC"), 
          type = "bar")%>% 
  layout(title = "Survival Rate by Passenger Class", 
         xaxis = list(title = "Passenger Class"), 
         yaxis = list(title = "Survival Rate (%)"), 
         legend = list(title = list(text = "Survival"), 
                       bgcolor = "white", bordercolor = "gray", borderwidth = 1))

```
Row
-------------------------------------

```{r}
plot_ly(data, x = ~Age, y = ~Fare, mode = "markers",
        type = "scatter", color = ~factor(Survived), 
        colors = c("#008080", "#FFD1DC"), 
        marker = list(opacity = 0.5)) %>% 
  layout(title = "Titanic Passenger Age vs. Fare",
         legend = list(title = list(text = "Survival")),
         xaxis = list(title = "Age"), 
         yaxis = list(title = "Fare"),
         annotations = list(x = 0.5, y = -0.15, 
                            xref = "paper", yref = "paper",
                            showarrow = FALSE))

```

```{r}
plot_ly(data,  x = ~Pclass,  y = ~Fare, type = "box", 
        color = ~factor(Pclass), colors = c("#008080", "#800020", "#FFD1DC"), 
        legendgroup = ~factor(Pclass), 
        hovertemplate = paste("Pclass: %{x}<br>", "Fare: %{y:$,.2f}<br>")) %>% 
  layout(title = "Fare and Pclass",
         xaxis = list(title = "Passenger Class"),
         yaxis = list(title = "Fare (USD)"),
         legend = list(title = list(text = "Class", font = list(size = 14)), 
                       tracegroupgap = 10, traceorder = "reversed", 
                       font = list(size = 12)))

```
Explanations
=================================

## Graph1

Graph1 - This graph is a scatter plot that displays the relationship between two variables: the age and fare of passengers on the Titanic. Each point on the plot represents a single passenger, and the position of the point corresponds to the age and fare of that passenger.
The color of each point represents the survival status of the passenger, with blue indicating that the passenger did not survive and pink indicating that the passenger did survive. The legend on the graph provides a key to the color scheme.
There appears to be a cluster of blue markers in the lower-left corner of the graph, which suggests that many of the passengers who did not survive were younger and paid a lower fare.
The pink markers are more spread out across the graph, which suggests that passengers who survived were of varying ages and paid varying fares.
The majority of passengers on the Titanic paid fares of $100 or less, as indicated by the concentration of markers along the left side of the graph.
There are a few outliers in the data, such as the passenger who paid the highest fare (marked by a pink marker), and the older passenger who paid a very low fare (marked by a blue marker).
The graph provides a visual representation of the correlation between age and fare. While there is no clear trend line or strong correlation between these variables, it is evident that there were passengers of all ages who paid a wide range of fares.

## Graph2 

Graph2 - The graph shows the survival rate of passengers by passenger class on the Titanic. The x-axis represents the passenger class (1st, 2nd, and 3rd), and the y-axis represents the percentage of passengers who survived. The bars are colored based on the survival outcome: grey for passengers who did not survive and pink for passengers who survived.
From the graph, we can see that the survival rate is highest for passengers in the first class, followed by the second class, and then the third class. This suggests that passenger class was a significant factor in determining survival rates on the Titanic.
Overall, the graph provides insight into the relationship between passenger class and survival rates on the Titanic and highlights the importance of socio-economic factors in determining survival outcomes during disasters.

## Graph3 

Graph3 - The pie chart shows the survival rates of passengers aboard the Titanic. The chart is divided into two sections: "Survived" and "Not Survived", each represented by a slice of the pie. The size of each slice corresponds to the percentage of passengers in that category.
From the chart, we can see that roughly 42% of passengers survived the disaster, while the remaining 58% did not. This highlights the severity of the disaster and the relatively low survival rates.
The chart is also color-coded using a custom color palette with shades of light blue and deep pink. The legend shows which color corresponds to each section of the chart. The chart is interactive, so you can hover over each slice to see the exact percentage and count of passengers in that category.
Overall, the pie chart provides a quick and visually appealing way to understand the survival rates of passengers aboard the Titanic.

## Graph4

Graph4 - The box plot shows the distribution of the fares paid by passengers in each passenger class (1st, 2nd, and 3rd). 
We can see that the fares for 1st class passengers had a much wider range than the fares for 2nd and 3rd class passengers. The median fare for 1st class was also much higher than the median fares for 2nd and 3rd class. There were some outliers in all three passenger classes, but they were more numerous and farther from the median in 1st class.
Overall, this plot shows how the fares paid by passengers varied depending on their passenger class, with 1st class passengers paying much higher fares on average than 2nd and 3rd class passengers.

## Relationship in all the dash

Relationship in all the dash - It can be seen that the graphs in the dashboard complement each other in order to provide a complete picture of the data. We first used simple relative graphs to get a general and broader understanding of the data. Then, we created complex plots that use more features to analyze the data at a finer resolution. In our opinion, the connections between the plots in the dashboard enhance the user's understanding.