Home > Blockchain >  Adding additional standard errors to different condition (ggplot2)
Adding additional standard errors to different condition (ggplot2)

Time:06-20

My standard error for young adults is 1.76, but I need to have different error bars for my older adults (1.937).

This is my code for my data frame, how do I make 1.76 specific to upper/lower bounds for young adults, and 1.94 for older adults?

    viz_data_one <- tibble(
  age_group = c(rep("Young Adult", 4), rep("Older Adult", 4)),
  MemoryAccuracy = c(32.8, 28.448, 27.672, 27.075, 29.667, 28.944, 27.556, 28.889),
  upper = MemoryAccuracy   1.76,
  lower = MemoryAccuracy - 1.76,
  reward = rep(c("Self High Value", "Self Low Value", "Other High Value", "Other Low Value"), 2)
) %>% 
  mutate(
    reward = as_factor(reward) %>% fct_relevel("Self High Value",
                                               "Self Low Value",
                                               "Other High Value",
                                               "Other Low Value")
  )

CodePudding user response:

You may try

viz_data_one %>%
  mutate(upper = MemoryAccuracy   ifelse(age_group == "Young Adult", 1.76, 1.94),
         lower = MemoryAccuracy - ifelse(age_group == "Young Adult", 1.76, 1.94))

  age_group   MemoryAccuracy upper lower reward          
  <chr>                <dbl> <dbl> <dbl> <fct>           
1 Young Adult           32.8  34.6  31.0 Self High Value 
2 Young Adult           28.4  30.2  26.7 Self Low Value  
3 Young Adult           27.7  29.4  25.9 Other High Value
4 Young Adult           27.1  28.8  25.3 Other Low Value 
5 Older Adult           29.7  31.6  27.7 Self High Value 
6 Older Adult           28.9  30.9  27.0 Self Low Value  
7 Older Adult           27.6  29.5  25.6 Other High Value
8 Older Adult           28.9  30.8  26.9 Other Low Value 

or

viz_data_one %>%
  mutate(upper = MemoryAccuracy   1.76   0.18*(age_group == "Older Adult"),
         lower = MemoryAccuracy - (1.76   0.18*(age_group == "Older Adult")))
  • Related