Visualisasi Data dari Dummy Data

Memanggil Library

Pastikan Package sudah didownload

install.packages(ā€œtidyverseā€) install.packages(ā€œtidyverseā€) install.packages(ā€œreadrā€)

library(esquisse)
library(ggplot2)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## āœ” dplyr     1.1.4     āœ” readr     2.1.5
## āœ” forcats   1.0.0     āœ” stringr   1.5.1
## āœ” lubridate 1.9.4     āœ” tibble    3.2.1
## āœ” purrr     1.0.2     āœ” tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## āœ– dplyr::filter() masks stats::filter()
## āœ– dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidymodels)
## ── Attaching packages ────────────────────────────────────── tidymodels 1.2.0 ──
## āœ” broom        1.0.7     āœ” rsample      1.2.1
## āœ” dials        1.3.0     āœ” tune         1.2.1
## āœ” infer        1.0.7     āœ” workflows    1.1.4
## āœ” modeldata    1.4.0     āœ” workflowsets 1.1.0
## āœ” parsnip      1.2.1     āœ” yardstick    1.3.2
## āœ” recipes      1.1.0     
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## āœ– scales::discard() masks purrr::discard()
## āœ– dplyr::filter()   masks stats::filter()
## āœ– recipes::fixed()  masks stringr::fixed()
## āœ– dplyr::lag()      masks stats::lag()
## āœ– yardstick::spec() masks readr::spec()
## āœ– recipes::step()   masks stats::step()
## • Dig deeper into tidy modeling with R at https://www.tmwr.org
library(readr)

Memanggil Data External (.csv)

data_customer <- read_csv("C:/Users/MUTHI'AH IFFA/Downloads/Semester 4/Visualisasi Data/customer data.csv")
## Rows: 30 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): first_name, gender, visit, credit card type, product, total purchase
## dbl (2): id, credit card id
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
data_customer
## # A tibble: 30 Ɨ 8
##       id first_name     gender visit `credit card id` `credit card type` product
##    <dbl> <chr>          <chr>  <chr>            <dbl> <chr>              <chr>  
##  1     1 Kara-lynn Del… Bigen… 12/1…          3.57e15 jcb                Sauce …
##  2     2 Anderea Fisk   Female 20/1…          3.56e15 jcb                V8 Pet 
##  3     3 Twyla Durrand  Female 6/1/…          3.58e15 jcb                C - Pl…
##  4     4 Cristabel Mor… Female 7/1/…          3.55e15 jcb                Calyps…
##  5     5 Tiffanie Pyke… Female 23/1…          3.04e13 diners-club-carte… Juice …
##  6     6 Edlin Pitrelli Non-b… 4/1/…          3.62e13 diners-club-inter… Pomello
##  7     7 Margette Metz… Female 8/1/…          3.56e15 jcb                Energy…
##  8     8 Gus Trayford   Female 13/1…          3.54e15 jcb                Juice …
##  9     9 Nikolos Le Br… Male   19/1…          4.94e17 switch             Beer -…
## 10    10 Melanie South… Female 6/1/…          3.54e15 jcb                Plate …
## # ℹ 20 more rows
## # ℹ 1 more variable: `total purchase` <chr>

Menggunakan esquisser untuk Memvisualisasikan Data

# esquisse::esquisser("data_customer")

Penerapan Data Kategori dengan Mengekstrak Kode dari essquisse

Diagram Batang

ggplot(data_customer) +
  aes(x = `credit card type`) +
  geom_bar(fill = "#0C4C8A") +
  labs(
    x = "credit type",
    y = "amount",
    title = "CUSTOMER'S CREDIT TYPE"
  ) +
  coord_flip() +
  theme_minimal() +
  theme(
    axis.text.y = element_text(face = "bold",
    size = 12L),
    axis.text.x = element_text(face = "bold")
  )

Heatmap

ggplot(data_customer) +
  aes(x = `credit card type`, fill = visit) +
  geom_bar() +
  scale_fill_viridis_d(option = "plasma", direction = 1) +
  labs(
    x = "credit card type",
    y = "amount",
    title = "CUSTOMER'S VISIT BY CREDIT CARD"
  ) +
  theme_minimal() +
  theme(
    axis.text.y = element_text(face = "bold"),
    axis.text.x = element_text(face = "bold",
    size = 6L,
    angle = 10L)
  )