Reputation: 144
I splitted a dataframe to a list, which looks like this:
data <- list(data.frame(name = sample(c("John","Jo","Marc","Donald Dumb"),3, replace = T), sales = sample(1:10,3, replace = T)),
data.frame(name = sample(c("John","Jo","Marc","Donald Dumb"),3, replace = T), sales = sample(1:10,3, replace = T)))
data
I want too ggplot the sales over the different data.frames in the list, but I dont how exactly to do this. I tried unlist but the result isnt proper.
Thank you and stay healthy
Upvotes: 1
Views: 120
Reputation: 887781
Using tidyverse
library(purrr)
library(dplyr)
library(ggplot2)
map(data, ~ .x %>%
ggplot(aes(x = name, y = sales)) +
geom_col(aes(fill = name), color = 'black'))
Upvotes: 1
Reputation: 39613
Try this:
library(ggplot2)
#Plot
lapply(data, function(x) ggplot(x,aes(x=name,y=sales))+
geom_col(aes(fill=name),color='black'))
Upvotes: 1