ggplot中的facet函数如何用于创建直方图,以可视化数据集中所有变量的分布?

这是我想可视化的变量的示例

id  post.test.score  pre.test.score  messages  forum.posts  av.assignment.score
1        0.37             0.48         68          7               0.19
2        0.52             0.37         83         22               0.28
3        0.42             0.37         81          7               0.25
4        0.56             0.34         94         14               0.27
5        0.25             0.39         42         11               0.07
daneee 回答:ggplot中的facet函数如何用于创建直方图,以可视化数据集中所有变量的分布?

我已经从上面的帖子中复制了数据,因此您可以跳过变量分配

library("tidyverse")

df <- read.table(file = "clipboard",header = T) %>% 
  as_tibble()

在将数据结构传递给ggplot之前,您需要稍作修改。使用tidyr::gather将每个测试名称放入一个变量中。然后通过管道传输到ggplot

df %>% 
  gather(test,value,-id) %>% 
  ggplot(aes(x = value)) +
  geom_histogram() +
  facet_grid(~test)
本文链接:https://www.f2er.com/2888008.html

大家都在问