I want to add the signifiacnce level for each points of my plot and then, separate the different level of significance by color I have this data :
tframe | trimSlope | trimSD |
---|---|---|
5 | 1.2138196 | 0.05958077 |
10 | 1.2118020 | 0.05748510 |
20 | 1.1903467 | 0.05208732 |
... | ... | ... |
to reproduce the data frame easily :
structure(list(tframe = c(5, 10, 15, 20, 30, 40, 50, 60, 90,
120, 180, 240, 300, 480, 900, 1800, 3600, 28800), species = c("Barbar",
"Barbar", "Barbar", "Barbar", "Barbar", "Barbar", "Barbar", "Barbar",
"Barbar", "Barbar", "Barbar", "Barbar", "Barbar", "Barbar", "Barbar",
"Barbar", "Barbar", "Barbar"), ineqMean = c(0.53104647399313,
0.529297808367612, 0.525839141416682, 0.523942046846265, 0.52015928420821,
0.518572691198356, 0.51511657232463, 0.516568872398126, 0.511999139793283,
0.511939221736915, 0.508740279266857, 0.505224606372793, 0.501518089116363,
0.499808187352849, 0.491227360987496, 0.4848439609884, 0.469461408463629,
0.414520902218365), ineqSD = c(0.240454548676913, 0.242024196245511,
0.243296542621781, 0.244848758571896, 0.246346408286188, 0.246855066968381,
0.24874025357451, 0.248373465513351, 0.249666296730884, 0.249737396611995,
0.250617197261608, 0.252642650344299, 0.254532366888185, 0.255779214784082,
0.258922307090312, 0.261528662624724, 0.271358143507595, 0.31225287692273
), trimSlope = c(1.21381956965976, 1.21180197611039, 1.20025777497667,
1.19034669771223, 1.18015387908413, 1.16704208709911, 1.15485377092914,
1.15004735545657, 1.13037958715777, 1.1207384447301, 1.11122218773119,
1.10897233423084, 1.09343555562548, 1.07597987336347, 1.0552313502822,
1.02714867784966, 1.01874318671967, 0.997267460326558), trimSD = c(0.0595807674313792,
0.0574850962929153, 0.0553699352357688, 0.0520873210646193, 0.0511378415143001,
0.0480448502673866, 0.0466519422226488, 0.0454344459587024, 0.0422792122257447,
0.0406831265017169, 0.038142436210773, 0.0379194407048026, 0.036217855188957,
0.0327675134394643, 0.0300492301761473, 0.0279263379108475, 0.0297584207536629,
0.0321719581188545), trimTrend = c("Strong increase (p<0.05)",
"Strong increase (p<0.05)", "Strong increase (p<0.05)", "Strong increase (p<0.05)",
"Strong increase (p<0.05)", "Moderate increase (p<0.05)", "Moderate increase (p<0.05)",
"Moderate increase (p<0.05)", "Moderate increase (p<0.05)", "Moderate increase (p<0.05)",
"Moderate increase (p<0.05)", "Moderate increase (p<0.05)", "Moderate increase (p<0.05)",
"Uncertain", "Uncertain", "Uncertain", "Uncertain", "Uncertain"
), col = c("#006400", "#006400", "#006400", "#006400", "#006400",
"#00CD00", "#00CD00", "#00CD00", "#00CD00", "#00CD00", "#00CD00",
"#00CD00", "#00CD00", "#BEBEBE", "#BEBEBE", "#BEBEBE", "#BEBEBE",
"#BEBEBE")), row.names = c(NA, -18L), class = c("tbl_df", "tbl",
"data.frame"))
And I want a result like this :
I alreday try to use the geom_signif function but that doesn't work and I have theis error meassage :
Error in geom_signif()
:
! Problem while computing stat.
ℹ Error occurred in the 4th layer.
Caused by error in setup_params()
:
! Can only handle data with groups that are plotted on the x-axis
my code is :
using ggplot2 and ggsignif packages
p <-
ggplot(df, aes(x = tframe, y = trimSlope)) +
geom_smooth(aes(x = tframe, y = trimSlope),
method = "loess", col = "black"
) +
geom_errorbar(aes(ymin = trimSlope - trimSD, ymax = trimSlope + trimSD),
width = .2
) +
geom_point(aes(x = tframe, y = trimSlope)) +
# add significance
geom_signif(comparisons = list(c(5, 10)),
map_signif_level=TRUE) +
# rtrim horizontal line at 1
geom_hline(yintercept = 1, linetype = "dashed", color = "red") +
# set x scale as log
scale_x_log10() +
labs(
x = "time frame in seconds (log scale)",
y = "mean indice values (trim slope) ± SE"
) +
# background and facetting
theme(panel.background = element_rect(
fill = "antiquewhite1",
colour = "blue"
))
I precise that my x axis is in log scale. So what I can do ?