1

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.

enter image description here

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:

enter image description here

But on my R it goes like this:

enter image description here

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")

Andre M
  • 11
  • 2
  • Can you post a sample data? Otherwise, you are unlikely to receive any help. SO users are trying to help people, but they do not necessarily have time to type your data in the picture. – jazzurro Nov 03 '19 at 02:16
  • I recommend you to read [this question](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – jazzurro Nov 03 '19 at 03:08
  • Thanks Jazzurro and I'm sorry again! – Andre M Nov 03 '19 at 03:26
  • No worries. Hope you can arrange a sample data for SO users. – jazzurro Nov 03 '19 at 03:33
  • Very thanks bro, edited the post and inserted the sample data now. – Andre M Nov 03 '19 at 03:40
  • Is `dados` identical to `data` in your code? – jazzurro Nov 03 '19 at 03:40
  • I wonder if [this question](https://stackoverflow.com/questions/32842923/specify-error-bars-with-ggplot-and-facet-grid) helps you. [This question](https://stackoverflow.com/questions/44872951/how-do-i-add-se-error-bars-to-my-barplot-in-ggplot2) is also similar to the previous question. – jazzurro Nov 03 '19 at 03:55
  • I tried to do this graph too, but it didn't work out as much as the one I posted! However I try again with these scripts – Andre M Nov 03 '19 at 03:57
  • `ggplot(dados, aes(x = Dose, y = mortalidade)) + stat_summary(geom = "bar", fun.y = mean, position = "dodge") + stat_summary(geom = "errorbar", fun.data = mean_se, position = "dodge") + facet_wrap (~ Stage) + theme_bw (16) + theme(axis.text.x = element_text (angle = 45, hjust = 1, vjust = 1))` It seems that this code is producing what you are after. – jazzurro Nov 03 '19 at 04:23
  • Thank you bro worked perfectly, I even managed to make the graphics that I had failed to do earlier. – Andre M Nov 03 '19 at 23:47

0 Answers0