Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R GG在列表上打印或列表到数据帧_R_Ggplot2 - Fatal编程技术网

R GG在列表上打印或列表到数据帧

R GG在列表上打印或列表到数据帧,r,ggplot2,R,Ggplot2,我将一个数据帧拆分为一个列表,如下所示: 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

我将一个数据帧拆分为一个列表,如下所示:

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
data试试这个:

library(ggplot2)
#Plot
lapply(data, function(x) ggplot(x,aes(x=name,y=sales))+
         geom_col(aes(fill=name),color='black'))
试试这个:

library(ggplot2)
#Plot
lapply(data, function(x) ggplot(x,aes(x=name,y=sales))+
         geom_col(aes(fill=name),color='black'))

使用
tidyverse

library(purrr)
library(dplyr)
library(ggplot2)
map(data, ~ .x %>%
               ggplot(aes(x = name, y = sales)) +
                geom_col(aes(fill = name), color = 'black'))

使用
tidyverse

library(purrr)
library(dplyr)
library(ggplot2)
map(data, ~ .x %>%
               ggplot(aes(x = name, y = sales)) +
                geom_col(aes(fill = name), color = 'black'))

你到底希望结果是什么样的?您是要创建一个绘图还是多个绘图?您希望结果是什么样的?您正在尝试创建一个绘图还是多个绘图?Thx完成了作业Thx完成了作业