Trying to use Errorbar in this code

I have this code that thanks to everyone who helped me so far, I am trying to add error bar but it does not work

library(dplyr)
library(readr)
library(ggplot2)

url <- "https://raw.githubusercontent.com/MohJumper/VisualAuditoryModality/master/clean_test_master2.csv"
clean_test_master2 <- read.csv(url)

# code been used
clean_test_master2 %>%
    mutate(Reproduction_Type = case_when(
      visbility == 1 & soundvolume == 0 ~ "Visual",
      visbility == 0 & soundvolume == 1 ~ "Auditory",
      visbility == 0 & soundvolume == 0 ~ "Empty")) %>%
    mutate_at(vars(Reproduction_Type), factor) %>%
    mutate(Opening_text_new = ifelse(Opening_text == "Now focus on the Image", "Now Attend to Visual",
                                     "Now Attend to Auditory")) %>%
    ggplot(aes(x = stim_ending_t, y = m, color = Reproduction_Type)) +
    geom_line(aes(linetype = Reproduction_Type)) +
    geom_point(aes(color = Reproduction_Type, shape = Reproduction_Type))+
    scale_x_continuous(name = "Sample Durations in Seconds",limits=c(1, 3.5)) +
    scale_y_continuous(name = "Mean Responses", limits=c(1, 3.5)) +
    geom_abline(intercept = 0, slope = 1, linetype="dashed") +
    theme_bw() +
    theme(legend.background = element_rect(fill = "darkgray"),
      legend.key = element_rect(fill = "white", color = NA),
      legend.key.size = unit(1.9, "cm"),
      axis.title.y=element_text(size=15),
      axis.text.x=element_text(size=15),
      legend.key.width = unit(0.01,"cm")) +
    facet_wrap(~Opening_text_new)

Here are the lines I tried but did not work:

geom_errorbar(aes(ymax=stim_ending_t+m, ymin=stim_ending_t-m), width=0.2, size=1, color="black") +
geom_errorbar(data=new_ce, mapping=aes(x = stim_ending_t, ymin=upper, ymax=lower), width=0.2, size=1, color="black") +

I added error bars based on the value of the sd column. I also removed the code setting the x and y scales because it was preventing the drawing of some of the error bars. You will have to adjust the scale to your liking.

library(dplyr)

library(readr)
#> Warning: package 'readr' was built under R version 3.5.3
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 3.5.3

url <- "https://raw.githubusercontent.com/MohJumper/VisualAuditoryModality/master/clean_test_master2.csv"
clean_test_master2 <- read.csv(url)

# code been used
clean_test_master2 %>%
  mutate(Reproduction_Type = case_when(
    visbility == 1 & soundvolume == 0 ~ "Visual",
    visbility == 0 & soundvolume == 1 ~ "Auditory",
    visbility == 0 & soundvolume == 0 ~ "Empty")) %>%
  mutate_at(vars(Reproduction_Type), factor) %>%
  mutate(Opening_text_new = ifelse(Opening_text == "Now focus on the Image", "Now Attend to Visual",
                                   "Now Attend to Auditory")) %>%
  ggplot(aes(x = stim_ending_t, y = m, color = Reproduction_Type)) +
  geom_line(aes(linetype = Reproduction_Type)) +
  geom_point(aes(color = Reproduction_Type, shape = Reproduction_Type))+
  geom_errorbar(aes(ymin = m - sd, ymax = m + sd)) +
  #scale_x_continuous(name = "Sample Durations in Seconds",limits=c(1, 3.5)) +
  #scale_y_continuous(name = "Mean Responses", limits=c(1, 3.5)) +
  geom_abline(intercept = 0, slope = 1, linetype="dashed") +
  theme_bw() +
  theme(legend.background = element_rect(fill = "darkgray"),
        legend.key = element_rect(fill = "white", color = NA),
        legend.key.size = unit(1.9, "cm"),
        axis.title.y=element_text(size=15),
        axis.text.x=element_text(size=15),
        legend.key.width = unit(0.01,"cm")) +
  facet_wrap(~Opening_text_new)

Created on 2019-11-04 by the reprex package (v0.3.0.9000)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.