Open kimpro82 opened 8 months ago
# 필요한 패키지 불러오기
library(ggplot2)
# 자유도 값 정의
df_values <- c(5, 10, 15, 20, 25, 30)
# x 값 범위 설정
x <- seq(-4, 4, length.out = 1000)
# 데이터 프레임 생성
df <- data.frame(x = rep(x, length(df_values)),
density = c(sapply(df_values, function(df) dt(x, df))),
distribution = rep(c("t-distribution", "Normal distribution"), each = length(x)))
# 체계적인 색상 팔레트
my_palette <- c("#1f78b4", "#33a02c")
# 그림 그리기
ggplot(df, aes(x = x, y = density, color = distribution)) +
geom_line(size = 1) +
scale_color_manual(values = my_palette) +
facet_wrap(~ distribution, ncol = 2, scales = "free_y") +
labs(title = "Comparison of t-distribution and Normal distribution",
x = "x", y = "Density") +
theme_minimal()
My brother-in-law asked, and I happened to be bored