0

I am trying to generate multiple graphs using map() function to substitute this list of copy/paste:

rvb1 <- ggplot(df)+ geom_bar(aes(x=rvb1))
rvb2 <- ggplot(df)+ geom_bar(aes(x=rvb2))
rvb3 <- ggplot(df)+ geom_bar(aes(x=rvb3))
rvb4 <- ggplot(df)+ geom_bar(aes(x=rvb4))
rvb5 <- ggplot(df)+ geom_bar(aes(x=rvb5))
rvb6 <- ggplot(df)+ geom_bar(aes(x=rvb6))

I am trying this one:

map(select(df, rvb1.17:rvb6.17), ~ggplot(.)+ geom_bar(aes(x=.)))

But I am receiving the following error: Error: 'data' must be a data frame, or other object coercible by 'fortify()', not a numeric vector

Could some good soul helpme with this task?

Tormod
  • 83
  • 6
  • Can you share a minimal reproducible example? – markus Jul 02 '20 at 18:25
  • 1
    Relevant: [ggplot2 - create a barplot for every column of a dataframe](https://stackoverflow.com/questions/52822840/ggplot2-create-a-barplot-for-every-column-of-a-dataframe) – markus Jul 02 '20 at 18:31
  • 2
    the error is because you are trying to use `map` over a data frame, the output from `select()`, so each call to `ggplot()` is only getting a single column as a vector and thus `ggplot` yells at you. Confirm with `map(select(df, rvb1.17:rvb6.17), print)` – Nate Jul 02 '20 at 19:29

0 Answers0