데이터 시각화
Sank Diagram 으로 QC 데이터 시각화 하기(ggalluvial)
r-code-for-data-analysis
2023. 5. 29. 08:15
날짜별 제품의 신뢰성 데이터를 측정을 하고, Spec을 정해서 Pass, Fail을 정한다고 해보자.
제품의 특정 position1 과 position2 중 어떤 위치에서 불량율이 높인지를 보는데 용이한 패키지가 있다.
바로 "ggalluvial" 패키지이다. 이걸 이용한 그래프를 Sank Diagram이라고 한다.
https://corybrunson.github.io/ggalluvial/
Alluvial Plots in ggplot2
Alluvial plots use variable-width ribbons and stacked bar plots to represent multi-dimensional or repeated-measures data with categorical or ordinal variables; see Riehmann, Hanfler, and Froehlich (2005) <doi:10.1109/INFVIS.2005.1532152> and Rosvall and Be
corybrunson.github.io
간단한 예제
1. 날짜별 제품의 위치1 (1~4번) 과 위치2 (5번~8번)의 저항 데이터를 불러온다.
2. 데이터 전치리와 시각화
df %>% pivot_longer(cols = `1번`: `8번`, names_to = "position", values_to = "resistance") %>%
mutate(side = ifelse(position %in% c("1번", "2번", "3번", "4번"), "Position1", "Posision2")) %>%
mutate(decision = ifelse(resistance < spec, "pass", "fail")) %>%
mutate(decision = factor(decision, levels=c("pass", "fail"))) %>%
group_by(세정.일, side, decision) %>% summarise(Freq = sum(ifelse(decision == "pass", 1, -1)), .groups = "drop") %>% mutate(Freq = abs(Freq)) %>%
ggplot(aes(axis1 = 세정.일, axis2 = side, axis3 = decision,
y = Freq)) +
scale_x_discrete(limits = c("날짜", "side", "decision"), expand = c(.2, .05)) +
xlab("Demographic") +
geom_alluvium(aes(fill = decision)) +
geom_stratum() +
geom_text(stat = "stratum", aes(label = after_stat(stratum))) +
theme_minimal() +
ggtitle("QC measurement Data",
"stratified by date and side position (Pass : R < spec Ω, Fail : R ≥ spec Ω)")
3. 결과 보기
728x90
반응형