Skip to content

Instantly share code, notes, and snippets.

@hadley
Created September 30, 2020 12:32
Show Gist options
  • Save hadley/fcfc99dc05478c8ab8e383223d56d099 to your computer and use it in GitHub Desktop.
Save hadley/fcfc99dc05478c8ab8e383223d56d099 to your computer and use it in GitHub Desktop.
library(tidyverse)

simple_data <- tibble(
  group = factor(rep(c("A", "B"), each = 15)),
  subject = 1:30,
  score = c(rnorm(15, 40, 20), rnorm(15, 60, 10))
)

simple_data_se <- simple_data %>% 
  group_by(group) %>% 
  summarise(mean_se(score))
#> `summarise()` ungrouping output (override with `.groups` argument)
simple_data_se
#> # A tibble: 2 x 4
#>   group     y  ymin  ymax
#>   <fct> <dbl> <dbl> <dbl>
#> 1 A      40.1  35.9  44.4
#> 2 B      62.6  59.0  66.2

simple_data_se%>% 
  ggplot(aes(group, y)) + 
  geom_col() + 
  geom_errorbar(aes(ymin = ymin, ymax = ymax), width = 0.5)

Created on 2020-09-30 by the reprex package (v0.3.0.9001)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment