0
我想繪製使用ggplot2繪製均值= 3和df = 1.5的t-分佈的密度曲線。但它應該是3左右對稱的,所以我不能使用非中心參數。使用ggplot2繪製移動t分佈
ggplot(data.frame(x = c(-4, 10)), aes(x = x)) +
stat_function(fun = dt, args = list(df = 1.5))
有沒有辦法簡單地沿x軸移動分佈?
我想繪製使用ggplot2繪製均值= 3和df = 1.5的t-分佈的密度曲線。但它應該是3左右對稱的,所以我不能使用非中心參數。使用ggplot2繪製移動t分佈
ggplot(data.frame(x = c(-4, 10)), aes(x = x)) +
stat_function(fun = dt, args = list(df = 1.5))
有沒有辦法簡單地沿x軸移動分佈?
你也可以做一個自定義函數爲您轉移t分佈:
custom <- function(x) {dt(x - 3, 1.5)}
ggplot(data.frame(x = c(-4, 10)), aes(x = x)) +
stat_function(fun = custom)
一個簡單的解決方法就是改變標籤來代替:
ggplot(data.frame(x = c(-4, 10)), aes(x = x)) +
stat_function(fun = dt, args = list(df = 1.5)) +
scale_x_continuous(breaks = c(0, 5, 10), labels = c(3, 8, 13))