Praktikum 04 - Visualisasi Data dengan ggplot2

Tugas Pertama untuk masing-masing Kelompok Kecil:

-Buat suatu Visualisasi Data, (data dari datasets di R, dengan catatan bahwa Visualisasi Data tersebut MELANGGAR 6 Prinsip dari Desain (ACCENT).

-Buat dalam rmarkdown, yang berisi syntax graphic, dan Catatan Pelanggaran.

-Upload dalam NewLMS berupa html paling lambat 8 Maret 2021 pukul 23.59 WIB, jangan lupa ditaruh di Rpubs masing-masing.

Visualisasi Data

Package

Melakukan koneksi terhadap database pada R software adalah dengan menggunakan syntax berikut:

install.packages(c("tidyverse", "ggridges", "GGally", "plotly", "grid"), dependencies = TRUE)

Memanggil package yang akan digunakan:

library(tidyverse)
library(ggridges)
library(ggplot2)
library(GGally)
library(plotly)     # Untuk membuat plot interaktif
library(grid)
library(kableExtra)# Akan diperlukan untuk fungsi `arrange`

Data

library(datasets) #untuk data set crimtab
data(esoph)
esoph<-tibble::as_tibble(datasets::esoph)

Data yang digunakan pada praktikum kali ini adalah data esoph.

Data from a case-control study of (o)esophageal cancer in Ille-et-Vilaine, France.

esoph %>%  kbl() %>%  kable_styling()  %>% scroll_box(height = "200px")
agegp alcgp tobgp ncases ncontrols
25-34 0-39g/day 0-9g/day 0 40
25-34 0-39g/day 10-19 0 10
25-34 0-39g/day 20-29 0 6
25-34 0-39g/day 30+ 0 5
25-34 40-79 0-9g/day 0 27
25-34 40-79 10-19 0 7
25-34 40-79 20-29 0 4
25-34 40-79 30+ 0 7
25-34 80-119 0-9g/day 0 2
25-34 80-119 10-19 0 1
25-34 80-119 30+ 0 2
25-34 120+ 0-9g/day 0 1
25-34 120+ 10-19 1 1
25-34 120+ 20-29 0 1
25-34 120+ 30+ 0 2
35-44 0-39g/day 0-9g/day 0 60
35-44 0-39g/day 10-19 1 14
35-44 0-39g/day 20-29 0 7
35-44 0-39g/day 30+ 0 8
35-44 40-79 0-9g/day 0 35
35-44 40-79 10-19 3 23
35-44 40-79 20-29 1 14
35-44 40-79 30+ 0 8
35-44 80-119 0-9g/day 0 11
35-44 80-119 10-19 0 6
35-44 80-119 20-29 0 2
35-44 80-119 30+ 0 1
35-44 120+ 0-9g/day 2 3
35-44 120+ 10-19 0 3
35-44 120+ 20-29 2 4
45-54 0-39g/day 0-9g/day 1 46
45-54 0-39g/day 10-19 0 18
45-54 0-39g/day 20-29 0 10
45-54 0-39g/day 30+ 0 4
45-54 40-79 0-9g/day 6 38
45-54 40-79 10-19 4 21
45-54 40-79 20-29 5 15
45-54 40-79 30+ 5 7
45-54 80-119 0-9g/day 3 16
45-54 80-119 10-19 6 14
45-54 80-119 20-29 1 5
45-54 80-119 30+ 2 4
45-54 120+ 0-9g/day 4 4
45-54 120+ 10-19 3 4
45-54 120+ 20-29 2 3
45-54 120+ 30+ 4 4
55-64 0-39g/day 0-9g/day 2 49
55-64 0-39g/day 10-19 3 22
55-64 0-39g/day 20-29 3 12
55-64 0-39g/day 30+ 4 6
55-64 40-79 0-9g/day 9 40
55-64 40-79 10-19 6 21
55-64 40-79 20-29 4 17
55-64 40-79 30+ 3 6
55-64 80-119 0-9g/day 9 18
55-64 80-119 10-19 8 15
55-64 80-119 20-29 3 6
55-64 80-119 30+ 4 4
55-64 120+ 0-9g/day 5 10
55-64 120+ 10-19 6 7
55-64 120+ 20-29 2 3
55-64 120+ 30+ 5 6
65-74 0-39g/day 0-9g/day 5 48
65-74 0-39g/day 10-19 4 14
65-74 0-39g/day 20-29 2 7
65-74 0-39g/day 30+ 0 2
65-74 40-79 0-9g/day 17 34
65-74 40-79 10-19 3 10
65-74 40-79 20-29 5 9
65-74 80-119 0-9g/day 6 13
65-74 80-119 10-19 4 12
65-74 80-119 20-29 2 3
65-74 80-119 30+ 1 1
65-74 120+ 0-9g/day 3 4
65-74 120+ 10-19 1 2
65-74 120+ 20-29 1 1
65-74 120+ 30+ 1 1
75+ 0-39g/day 0-9g/day 1 18
75+ 0-39g/day 10-19 2 6
75+ 0-39g/day 30+ 1 3
75+ 40-79 0-9g/day 2 5
75+ 40-79 10-19 1 3
75+ 40-79 20-29 0 3
75+ 40-79 30+ 1 1
75+ 80-119 0-9g/day 1 1
75+ 80-119 10-19 1 1
75+ 120+ 0-9g/day 2 2
75+ 120+ 10-19 1 1
summary(esoph) #melihat ringkasan data
##    agegp          alcgp         tobgp        ncases         ncontrols    
##  25-34:15   0-39g/day:23   0-9g/day:24   Min.   : 0.000   Min.   : 1.00  
##  35-44:15   40-79    :23   10-19   :24   1st Qu.: 0.000   1st Qu.: 3.00  
##  45-54:16   80-119   :21   20-29   :20   Median : 1.000   Median : 6.00  
##  55-64:16   120+     :21   30+     :20   Mean   : 2.273   Mean   :11.08  
##  65-74:15                                3rd Qu.: 4.000   3rd Qu.:14.00  
##  75+  :11                                Max.   :17.000   Max.   :60.00

Contoh Visualisasi Data

esoph = esoph %>%  filter(agegp != '45-54')

myplot<-ggplot()+
  geom_point(aes(x=ncases,
                 y=ncontrols,
                 colour=factor(round(ncases)),
                 shape =factor(round(ncases))),
             data=esoph)+ scale_y_reverse()+
  labs(caption ="Scatter Plot Kasus Kanker vs Kontrol")+
  theme(axis.title.x=element_blank(),
        axis.title.y=element_blank())
myplot
## Warning: The shape palette can deal with a maximum of 6 discrete values because
## more than 6 becomes difficult to discriminate; you have 10. Consider
## specifying shapes manually if you must have them.
## Warning: Removed 7 rows containing missing values (geom_point).

Catatan Pelanggaran

Apprehension

Subtansi data disni tidak ada. Hubungan antar kasus kanker dengan jumlah kontrol tidak terlihat jelas. bisa saja kontrol ditambah jumlah orang yang terkena penyakit kanker tidak bertambah. Data yang perlu ditampilkan seharusnya hubungan konsumsi alkohol dan/atau konsumsi tembakau dengan jumlah penderita kanker atau hubungan konsumsi alkohol dan/atau konsumsi tembakau dengan control group.

Clarity

Bentuk shape yang bermacam membuat grafik menjadi tidak jelas. Tidak adanya label x dan label y menjadikan ketidakjelasan pada grafik. Legend juga tidak jelas karena masih dalam bentuk script R.

Consistency

Variabel kasus kanker di variable Y tidak bergerak dari 0-60 tetapi 60-0. Judul grafik diletakkan di bagian caption sehingga tidak konsisten dengan standar grafik.

Efficiency

Bentuk dan warna shape yang berbeda beda padahal artinya sama.

Necessity

Scater plot penderita kanker dan jumlah kontrol saja, tidak dibutuhkan. Perlu ditambahkan variabel kelompok umur, alkohol konsumsi dan/atau konsumsi tembakau.

Truthfulness

Tidak mengambarkan keadaan yang sebenar tentang kasus kanker tersebut. Pembuat grafik menghapus kelompok umur 45-54 tanpa adanya informasi di grafik dengan tujuan menjadikan pembaca salah paham.

Refrences

anonym . tanpa tahun .qplot: Quick plot with ggplot2 - R software and data visualization [2 Maret 2021]. http://www.sthda.com/english/wiki/qplot-quick-plot-with-ggplot2-r-software-and-data-visualization

Chang W. 2013. R Graphic Cookbook. California : O’Really Media. http://www.cookbook-r.com/

de Vries A, Meys J. tanpa tahun. How to Get Geoms in ggplot in R [4 Maret 2021]. https://www.dummies.com/programming/r/how-to-get-geoms-in-ggplot-in-r/

Dito GA, Anisa R. 2020. Visualisasi Data dengan ggplot2. [1 Maret 2021].https://rpubs.com/gdito/viz-ggplot2

Lilis D. tanpa tahun .R Graphics: Plotting in Color with qplot Part 2 [4 Maret 2021]. https://www.theanalysisfactor.com/r-programming-plotting-color-part-2-qplot/

RStudio . tanpa tahun . Data Visualization with ggplot2 Cheat Sheet [4 Maret 2021]. https://rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf

Turner S. 2010. Arrange multiple ggplot2 plots in the same image window [3 Maret 2021]. https://gettinggeneticsdone.blogspot.com/2010/03/arrange-multiple-ggplot2-plots-in-same.html

Wickham H, Danielle N, Pedersen TL. 2016. ggplot2: Elegant Graphics for Data Analysis. Texas: Springer. https://ggplot2-book.org/

Demikian, Terima Kasih