大家早上好,
我对图表的格式有疑问。
在这里,我将平均组大小表示为与海岸距离的函数。是否可以将每列除以每类小时的观察次数的百分比,同时保持初始列的大小代表平均值。
有我的数据:
dput(droplevels(df.long2[1:15, ]))
structure(list(Distance = c("1-40", "1-40", "1-40", "40-80",
"40-80", "40-80", "80-120", "80-120", "80-120", "120-160", "120-160",
"120-160", "160-225", "160-225", "160-225"), mean = c(6.66901408450704,
6.66901408450704, 6.66901408450704, 6.33333333333333, 6.33333333333333,
6.33333333333333, 10.2561403508772, 10.2561403508772, 10.2561403508772,
11.3986013986014, 11.3986013986014, 11.3986013986014, 23.7051282051282,
23.7051282051282, 23.7051282051282), erreur_std = c(0.63121621161232,
0.63121621161232, 0.63121621161232, 0.469878994871701, 0.469878994871701,
0.469878994871701, 1.29468464273019, 1.29468464273019, 1.29468464273019,
1.53421016593719, 1.53421016593719, 1.53421016593719, 4.00121147880924,
4.00121147880924, 4.00121147880924), count = c(142L, 142L, 142L,
312L, 312L, 312L, 285L, 285L, 285L, 143L, 143L, 143L, 78L, 78L,
78L), Heure = c("0-4", "4-8", "8-12", "0-4", "4-8", "8-12", "0-4",
"4-8", "8-12", "0-4", "4-8", "8-12", "0-4", "4-8", "8-12"), n = c(48L,
79L, 15L, 131L, 148L, 33L, 85L, 152L, 48L, 83L, 51L, 9L, 56L,
11L, 11L)), row.names = c(NA, -15L), class = c("tbl_df", "tbl",
"data.frame"))
但不幸的是,当我尝试制作这张图时,我得到了这个,因为线条累积
有我使用的脚本:
ggplot(df.long2, aes(x=Distance, y = mean, fill = Heure)) +
geom_col(position = "stack", fill='steelblue', color="gray", stat="identity")+
geom_errorbar(data = df.long2, aes(ymin = mean-erreur_std, ymax = mean+erreur_std), width = .2, position = position_dodge(width = 0.9))+
theme_bw() +
scale_x_discrete(limits=c("1-40", "40-80", "80-120", "120-160", "160-225")) +
labs(title = "Moyenne de la taille des groupes chez le dauphin commun \n(Delphinus delphis) en fonction de la distance à la côte ",
caption = "Source : Observatoire PELAGIS ",
x = "Distance à la côte (kilomètres)",
y = "Moyenne de la taille des groupes",
subtitle = "n=960") +
theme(plot.title = element_text(hjust = 0.5)) +
geom_text(aes(label=count), y=-0.5, hjust = 0.1, stat='count', colour="black", size=3) +
geom_text(aes(label= "n=" ), y= -0.5, hjust = 1.1, colour="black", size = 3)
预先感谢您的回复