#Latihan VDE

library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.3
#import dataset
titanic = read.csv("C:/Users/shafi/Downloads/titanic2.csv.csv")

#COntoh Visualisasi

#1 Perbandingan jenis kelamin titanic
ggplot(titanic, aes(x= Sex)) + 
  geom_bar(fill= 'pink') +
  labs(tittle = "Perbandingan Jenis Kelamin Penumpang Titanic")

#2 Perbandingan data selamat atau tidak berdasarkan kelas
ggplot(titanic, aes(x =factor(Pclass), fill = factor(Survived))) +
  geom_bar(position="fill") +
  labs(tittle = "Proporsi Survival berdasarkan Kelas")

#3 Distribusi Umur Penumpang
ggplot(titanic, aes(x =Age))+
  geom_histogram(bins =30, fill ='purple', colors = 'white')+
  labs(title ="Distribusi Umur Penumpang")
## Warning in geom_histogram(bins = 30, fill = "purple", colors = "white"):
## Ignoring unknown parameters: `colours`
## Warning: Removed 177 rows containing non-finite outside the scale range
## (`stat_bin()`).

#4 boxplot
ggplot(titanic, aes(x =factor(Survived), y=Age, fill= factor(Survived)))+
  geom_boxplot(outlier.color ='red')+
  labs(title ="boxplot")
## Warning: Removed 177 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

#Scatterplot
ggplot(titanic, aes(x= Age, y=Fare))+
  geom_point()+
  geom_smooth(method = "lm", color ='blue')+
  labs(title = "Pengaruh umur terhadapa harga tiket")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 177 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 177 rows containing missing values or values outside the scale range
## (`geom_point()`).