Visualisasi Proporsi

Data Automobile

Data yang digunakan adalah data automobile yang bersumber dari 1985 Ward's Automotive Yearbook. Data ini biasa digunakan untuk menentukan level asuransi yang akan diberikan. Data ini terdiri dari spesifikasi mobil dan level resiko asuransi yang ditetapkan. Nilai +3 menunjukkan bahwa mobil itu berisiko, -2 yang mungkin cukup aman. Data ini dapat di download pada link berikut ini: https://ipb.link/praktikum-visualisasidata

data <- read.csv("D:/Bahan Ajar/Automobile.csv")
head(data)
##   Level Jenis_mobil Bahan_bakar Jumlah_pintu   bodystyle lokasi_mesin
## 1     3 alfa-romero         gas          two convertible        front
## 2     3 alfa-romero         gas          two convertible        front
## 3     1 alfa-romero         gas          two   hatchback        front
## 4     2        audi         gas         four       sedan        front
## 5     2        audi         gas         four       sedan        front
## 6     2        audi         gas          two       sedan        front
##   Jarak_roda Panjang_mobil Lebar_mobil Tinggi_Mobil Tipe_mesin Ukuran_mesin
## 1       88.6         168.8        64.1         48.8       dohc          130
## 2       88.6         168.8        64.1         48.8       dohc          130
## 3       94.5         171.2        65.5         52.4       ohcv          152
## 4       99.8         176.6        66.2         54.3        ohc          109
## 5       99.4         176.6        66.4         54.3        ohc          136
## 6       99.8         177.3        66.3         53.1        ohc          136
##   Harga
## 1 13495
## 2 16500
## 3 16500
## 4 13950
## 5 17450
## 6 15250
data <- data %>% mutate_if(is.character, as.factor)
data$Level <- as.factor(data$Level)
a <- summarise(group_by(data, Level), mean(Harga, na.rm = TRUE))
head(a)
## # A tibble: 6 x 2
##   Level `mean(Harga, na.rm = TRUE)`
##   <fct>                       <dbl>
## 1 -2                         15782.
## 2 -1                         17331.
## 3 0                          14278.
## 4 1                          10738.
## 5 2                          10109.
## 6 3                          17221.

Visualisasi Data

Pie Chart

pie1 <- ggplot(a, aes(x="Level", y=`mean(Harga, na.rm = TRUE)`, fill=Level)) +
  geom_bar(stat="identity", width=1) +
  coord_polar("y", start=0)+
  ggtitle("Harga Mobil terhadap Resiko Asuransi")+
  theme_void()
pie1

Donut Chart

a$ymax <- cumsum(a$`mean(Harga, na.rm = TRUE)`)
a$ymin <- c(0, head(a$ymax, n=-1))
a$labelPosition <- (a$ymax+a$ymin)/2

ggplot(a, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill= Level))+
  geom_rect()+
  coord_polar(theta="y")+
  xlim(c(2,4))+
  theme_void()

Stacked-Bar Chart

bpt<- ggplot(a, aes(x="", y=`mean(Harga, na.rm = TRUE)`, fill=Level))+
  geom_bar(width = 1, stat = "identity")+
  theme_void()+
  ggtitle("Harga Mobil terhadap Resiko Asuransi")
bpt

Bar Chart

bp <- ggplot(data=a, aes(x=Level, y=`mean(Harga, na.rm = TRUE)`, fill=Level))+
  geom_bar(stat = "identity", color ="white")+
  theme_void()+
  ggtitle("Harga Mobil terhadap Resiko Asuransi")

bp

#area plot
ap <- ggplot(data, aes(x=Harga, fill=Level)) +
  geom_area(stat ="bin")+
  theme_void()+
  ggtitle("Harga Mobil terhadap Resiko Asuransi")
ap