Q:

Generate histograms out of dplyr pipe

I have a dataset that I want to group_by() and generate a histogram for each group. My current code is as follows:
df %>%
  group_by(x2) %>%
  with(hist(x3,breaks = 50))

This however generates a single histogram of the entirety of x3 rather than several chunks of x3 here is some example data
df = data.frame(x1 = rep(c(1998,1999,2000),9),
            x2 = rep(c(1,1,1,2,2,2,3,3,3),3),
            x3 = rnorm(27,.5))

desired output: 

actual output:

A:

I think it's time to advance to ggplot, for instance:
library(tidyverse)

df %>% 
  ggplot(aes(x = x3)) + 
  geom_histogram(bins = 50) + 
  facet_wrap(~x2) # optional: use argument "ncols = 1"

A:

My comment about do  is dated, I guess. ?do points us to the current ?group_walk:
df %>%
 group_by(x2) %>%
 group_walk(~ hist(.x$x3))

In versions of dplyr < 0.8.0, there is no group_walk, so you can use do:
df %>% 
  group_by(x2) %>%
  do(h = hist(.$x3))

Assuming you only want the side-effects of hist (printed histogram), not the returned values, you can add a %>% invisible() to the end of the chain to not print the resulting tibble.

