Persiapan Data

Memasukan package

library(readxl)

Memasukan data

data <- read_excel("data_kualitas_produk.xlsx")
data
## # A tibble: 28 × 4
##       No Tanggal `Jumlah produksi` `Bad Stock`
##    <dbl>   <dbl>             <dbl>       <dbl>
##  1     1       2               266          42
##  2     2       3               225          20
##  3     3       4               258          19
##  4     4       5               243          34
##  5     5       6               233          17
##  6     6       7               276          56
##  7     7       8               209          22
##  8     8       9               224          18
##  9     9      10               275          34
## 10    10      11               213          31
## # ℹ 18 more rows

Memeriksa data

head(data)
## # A tibble: 6 × 4
##      No Tanggal `Jumlah produksi` `Bad Stock`
##   <dbl>   <dbl>             <dbl>       <dbl>
## 1     1       2               266          42
## 2     2       3               225          20
## 3     3       4               258          19
## 4     4       5               243          34
## 5     5       6               233          17
## 6     6       7               276          56
str(data)
## tibble [28 × 4] (S3: tbl_df/tbl/data.frame)
##  $ No             : num [1:28] 1 2 3 4 5 6 7 8 9 10 ...
##  $ Tanggal        : num [1:28] 2 3 4 5 6 7 8 9 10 11 ...
##  $ Jumlah produksi: num [1:28] 266 225 258 243 233 276 209 224 275 213 ...
##  $ Bad Stock      : num [1:28] 42 20 19 34 17 56 22 18 34 31 ...

Membuat Diagram Kendali P

Menghitung proporsi

p = round(data$`Bad Stock` / data$`Jumlah produksi`,3)
p
##  [1] 0.158 0.089 0.074 0.140 0.073 0.203 0.105 0.080 0.124 0.146 0.120 0.162
## [13] 0.128 0.035 0.077 0.127 0.109 0.090 0.063 0.064 0.102 0.167 0.216 0.124
## [25] 0.067 0.083 0.077 0.108

Menghitung batas kendali

Menghitung rata-rata proporsi

mean_p = round(mean(p),3)
mean_p
## [1] 0.111

Menghitung batas kendali atas(UCL)

UCL = round(mean_p + (3*sqrt((mean_p*(1 - mean_p))/data$`Jumlah produksi`)),3)
UCL
##  [1] 0.169 0.174 0.170 0.171 0.173 0.168 0.176 0.174 0.168 0.176 0.170 0.177
## [13] 0.168 0.166 0.165 0.170 0.166 0.169 0.170 0.175 0.169 0.177 0.172 0.169
## [25] 0.174 0.167 0.168 0.173

Menghitung batas kendali bawah (LCL)

LCL = round(mean_p - (3*sqrt((mean_p*(1 - mean_p))/data$`Jumlah produksi`)),3)
LCL
##  [1] 0.053 0.048 0.052 0.051 0.049 0.054 0.046 0.048 0.054 0.046 0.052 0.045
## [13] 0.054 0.056 0.057 0.052 0.056 0.053 0.052 0.047 0.053 0.045 0.050 0.053
## [25] 0.048 0.055 0.054 0.049

Membuat diagram kendali

# Memuat paket ggplot2
library(ggplot2)

# Data untuk plotting (pastikan data 'p', 'UCL', 'LCL', dan 'mean_p' sudah ada)
data_p <- data.frame(
  Sampel = 1:length(p),
  Proporsi = p
)

# Plot menggunakan ggplot2
ggplot(data_p, aes(x = Sampel, y = Proporsi)) +
  geom_line(aes(color = "Proporsi")) +  # Garis proporsi
  geom_hline(aes(yintercept = mean_p, color = "Rata-rata"), linetype = "dashed") +  # Garis rata-rata
  geom_line(aes(y = UCL, color = "Batas Kendali UCL"), linetype = "dashed") +  # Garis UCL
  geom_line(aes(y = LCL, color = "Batas Kendali LCL"), linetype = "dashed") +  # Garis LCL
  labs(x = "Sampel", y = "Cacat per Unit", title = "Diagram Kendali P") +  # Label dan judul
  scale_color_manual(values = c("Proporsi" = "blue", "Rata-rata" = "green", 
                                "Batas Kendali UCL" = "red", "Batas Kendali LCL" = "red")) +  # Menentukan warna
  theme_minimal() +  # Tema minimal
  scale_y_continuous(limits = c(0,max(p))) +  # Batas y-axis
  theme(
    legend.position = "bottom",  # Posisi legenda
    legend.title = element_blank(),
    legend.text = element_text(),
    plot.title = element_text(hjust = 0.5)
  )

Membuat Diagram Kendali U

Menghitung u

u = round(data$`Bad Stock` / data$`Jumlah produksi`,3)
u
##  [1] 0.158 0.089 0.074 0.140 0.073 0.203 0.105 0.080 0.124 0.146 0.120 0.162
## [13] 0.128 0.035 0.077 0.127 0.109 0.090 0.063 0.064 0.102 0.167 0.216 0.124
## [25] 0.067 0.083 0.077 0.108

Menghitung batas kendali

Menghitung u bar

ubar = round(sum(data$`Bad Stock`)/sum(data$`Jumlah produksi`),3)
ubar
## [1] 0.11

Menghitung batas kendali atas(UCL)

ucl = round(ubar + (3*sqrt(ubar/data$`Jumlah produksi`)),3)
ucl
##  [1] 0.171 0.176 0.172 0.174 0.175 0.170 0.179 0.176 0.170 0.178 0.173 0.180
## [13] 0.170 0.169 0.167 0.173 0.168 0.171 0.172 0.177 0.171 0.180 0.175 0.171
## [25] 0.176 0.169 0.170 0.175

Menghitung batas kendali bawah (LCL)

lcl = round(ubar - (3*sqrt(ubar/data$`Jumlah produksi`)),3)
lcl
##  [1] 0.049 0.044 0.048 0.046 0.045 0.050 0.041 0.044 0.050 0.042 0.047 0.040
## [13] 0.050 0.051 0.053 0.047 0.052 0.049 0.048 0.043 0.049 0.040 0.045 0.049
## [25] 0.044 0.051 0.050 0.045

Membuat diagram kendali

# Memuat paket ggplot2
library(ggplot2)

# Data untuk plotting (pastikan data 'p', 'UCL', 'LCL', dan 'mean_p' sudah ada)
data_u <- data.frame(
  Sampel = 1:length(u),
  Proporsi = u
)

# Plot menggunakan ggplot2
ggplot(data_u, aes(x = Sampel, y = Proporsi)) +
  geom_line(aes(color = "Proporsi")) +  # Garis proporsi
  geom_hline(aes(yintercept = mean_p, color = "Ubar"), linetype = "dashed") +  # Garis rata-rata
  geom_line(aes(y = ucl, color = "Batas Kendali UCL"), linetype = "dashed") +  # Garis UCL
  geom_line(aes(y = lcl, color = "Batas Kendali LCL"), linetype = "dashed") +  # Garis LCL
  labs(x = "Sampel", y = "Cacat per Unit", title = "Diagram Kendali U") +  # Label dan judul
  scale_color_manual(values = c("Proporsi" = "blue", "Ubar" = "green", 
                                "Batas Kendali UCL" = "red", "Batas Kendali LCL" = "red")) +  # Menentukan warna
  theme_minimal() +  # Tema minimal
  scale_y_continuous(limits = c(0,max(p))) +  # Batas y-axis
  theme(
    legend.position = "bottom",  # Posisi legenda
    legend.title = element_blank(),
    legend.text = element_text(),
    plot.title = element_text(hjust = 0.5)
  )