I have a data frame with the mean ("Resultado" ) and standard deviation ("sd_Res") among other, for different laboratories ("Cod_participante") and chemical parameters ("Parametro"). I need to plot the density plots for each of them, grouped by "Parametro", in one plot, like that:
An example of the data frame is:
structure(list(Cod_participante = c("2517", "4012", "4266", "4667",
"5284", "6506"), Parametro = c("Aluminio total (Al)", "Aluminio total (Al)",
"Aluminio total (Al)", "Aluminio total (Al)", "Aluminio total (Al)",
"Aluminio total (Al)"), VE = c(1.51, 1.51, 1.51, 1.51, 1.51,
1.51), U_VE = c(0.1, 0.1, 0.1, 0.1, 0.1, 0.1), sd_EA = c(0.227023550978767,
0.227023550978767, 0.227023550978767, 0.227023550978767, 0.227023550978767,
0.227023550978767), Resultado = c(1.58, 1.63, 1.471, 1.5, 1.51,
1.59), U = c(0.06, 0.0458, 0.08, 0.03, 0.01, 0.05724), Zscore_abs = c(0.3,
0.5, 0.2, 0, 0, 0.4), Porc_U = c(3.79746835443038, 2.80981595092025,
5.43847722637661, 2, 0.662251655629139, 3.6), Z_crit = c(2.33333333333334,
5.24017467248908, -0.974999999999998, -0.666666666666667, 0,
2.79524807826695), P_menor_VE = c(0.00981532862864531, 8.02123371057561e-08,
0.835219870019689, 0.747507462453077, 0.5, 0.00259299513904498
), P_mayor_VE = c(0.990184671371355, 0.999999919787663, 0.164780129980311,
0.252492537546923, 0.5, 0.997407004860955), sd_Res = c(0.03,
0.0229, 0.04, 0.015, 0.005, 0.02862)), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
#> # A tibble: 6 x 13
#> Cod_participante Parametro VE U_VE sd_EA Resultado U Zscore_abs
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2517 Aluminio~ 1.51 0.1 0.227 1.58 0.06 0.3
#> 2 4012 Aluminio~ 1.51 0.1 0.227 1.63 0.0458 0.5
#> 3 4266 Aluminio~ 1.51 0.1 0.227 1.47 0.08 0.2
#> 4 4667 Aluminio~ 1.51 0.1 0.227 1.5 0.03 0
#> 5 5284 Aluminio~ 1.51 0.1 0.227 1.51 0.01 0
#> 6 6506 Aluminio~ 1.51 0.1 0.227 1.59 0.0572 0.4
#> # ... with 5 more variables: Porc_U <dbl>, Z_crit <dbl>, P_menor_VE <dbl>,
#> # P_mayor_VE <dbl>, sd_Res <dbl>
Created on 2021-03-02 by the reprex package (v1.0.0)
In this example, I ploted a density plot with mean ("Resultado")=0.11 and sd ("sd_Res")=0.005
library(ggplot2)
DF_rnorm_B<-data.frame(B=rnorm(10000,0.11,0.005))
ggplot(DF_rnorm_B,aes(B))+geom_density()
Created on 2021-03-02 by the reprex package (v1.0.0)
I have seen examples of how to generate density plots from different sources (like GRÁFICO de DENSIDAD en R ⚡ [con Selección de Ventana]), but I need to be able to generate a code that generates density plots grouped by parameter ("Parameter"), for each participant ("Cod_participant"), from the dataframe.
I hope this is understood.
Thank you very much.