绘制几个概率分布

问题描述 投票:0回答:1

我想可视化具有不同参数的对数正态概率分布。

我有以下

data.frame
参数:

 structure(list(country = c("v1", "v2", "v3", "v4", "v5", "v6", 
"v7", "v8", "v9"), mean = c(47.57, 44.91, 47.15, 44.44, 42.67, 
37.84, 37.91, 44.35, 54.76), sd = c(34.97, 34.4, 34.27, 33.92, 
34.82, 28.19, 30.18, 33.68, 40.48)), row.names = c(NA, -9L), class = "data.frame")

此外,使用以下代码,我生成以下图:

# Simulate data from the lognormal distribution
set.seed(123)
num_samples <- 10000  # Choose the desired number of samples
simulated_data <- lapply(1:9,FUN=function(x)data.frame(kost=rlnorm(num_samples, meanlog = 
parameters$meanlog_val[x], sdlog = parameters$sdlog_val[x]),country=country[x]))
table_plot<-bind_rows(simulated_data)

ggplot(table_plot,aes(x=kost,fill=country))+geom_density(alpha=0.3)+
  theme_classic()

然而,区分不同的形状并不那么容易。也许您知道如何更好地可视化这种差异?

r visualization ggplot2
1个回答
0
投票

您可能会考虑仅绘制平均值与标准差的图。

library(ggplot2)
library(ggrepel)
df <- data.frame(Mean=c(47.57, 44.91, 47.15, 44.44, 42.67, 37.84, 37.91, 44.35, 54.76),
  SD=c(34.97, 34.4, 34.27, 33.92, 34.82, 28.19, 30.18, 33.68, 40.48), 
  Country=paste("V", c(1:9), sep=""))

ggplot(df, aes(Mean, SD)) + geom_point() + geom_text_repel(aes(label = Country))

© www.soinside.com 2019 - 2024. All rights reserved.