Good Night Masters!
I would like to make a subdivided bar chart with standard error, but I am having difficulty because of my large amount of data, and I am unable to adjust and do. I have insect stage data (eggs, larvae, pupae and male and female adults). Photo below.
So I thought of dividing each stage by each chart, but I couldn't make the chart: The code I used was this:
data <- read.table (file.choose (), header = TRUE)
attach (data)
head (data)
if (! require ("pacman")) install.packages ("pacman") pacman :: p_load (readr, dplyr, ggplot2)
# Grouping according to treatment. Applies the sum of all observations (mortality) according to the clustering factor.
total_trat <- data%>%
group_by (dose)%>%
summarize (Stage = sum (mortality, na.rm = T))
total_trat
#To make the chart
ggplot (total_trat_local, aes (Dose, Mortality)) +
geom_col (alpha = 0.8, position = "dodge") +
facet_wrap (~ Stage) +
theme_bw (16) +
theme (axis.text.x = element_text (angle = 45, hjust = 1, vjust = 1))
# Deviation (SD)
media_trat_desv <- data%>% group_by (Dose)%>%
summarize (dev = sd (mortality, na.rm = T) / sqrt (n()), galls = mean (mortality, na.rm = T))
media_trat_desv
#Standard deviation as a function of each Dose and Stage.
mediana_trat_Stage_desv <- data%>% filter (Collection == 5)%>% group_by (Dose, Stage)%>%
summarize(dev = sd (mortality, na.rm = T) / sqrt (n ()), mortality = median (mortality, na.rm = T))
mediana_trat_Stage_desv
# subdivided chart
ggplot (median_trat_Stage_desv, aes (Dose, mortality)) +
geom_col (alpha = 0.8, position = "dodge") +
geom_errorbar (aes (ymin = mortality - dev, ymax = mortality + dev), width = 0.4, alpha = 0.8) +
facet_wrap (~ Stage) + theme_bw (16) + theme (axis.text.x = element_text (angle = 45, hjust = 1, vjust = 1))
I would like to get the chart below:
But on my R it goes like this:
Thanks!!
The data are project are below: dput(head(dados, 30))
dados <- structure(list(Dose = structure(c(11L, 11L, 11L, 11L, 11L, 15L,
15L, 15L, 15L, 15L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L,
13L, 14L, 14L, 14L, 14L, 14L, 16L, 16L, 16L, 16L, 16L), .Label = c ("AdultsF_0Control",
"AdultsF_10Gy", "AdultsF_15Gy", "AdultsF_20Gy", "AdultsF_5Gy",
"AdultsM_0Control", "AdultsM_10Gy", "AdultsM_15Gy", "AdultsM_20Gy",
"AdultsM_5Gy", "Eggs_0Control", "Eggs_10Gy", "Eggs_15Gy", "Eggs_20Gy",
"Eggs_5Gy", "Larvae_0Control", "Larvae_10Gy", "Larvae_15Gy",
"Larvae_20Gy", "Larvae_5Gy", "Pupae_0Control", "Pupae_10Gy",
"Pupae_15Gy", "Pupae_20Gy", "Pupae_5Gy"), class = "factor"),
Stage = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L, 4L), .Label = c("Adults_Female", "Adults_Male",
"Eggs", "Larvae", "Pupae"), class = "factor"), mortalidade = c(133L,
136L, 130L, 156L, 155L, 146L, 144L, 130L, 132L, 133L, 104L,
123L, 118L, 121L, 114L, 94L, 96L, 86L, 100L, 99L, 0L, 0L,
0L, 0L, 0L, 137L, 120L, 35L, 10L, 0L)), row.names = c(NA,
30L), class = "data.frame")