在 r 中绘制不同的列

plotting different columns in r

数据 = 110 列(x1:x100)(数字)

我正在尝试使用以下代码绘制所有列,

      x2=melt(x1)
      ggplot(x2,aes(x = value)) + 
      facet_wrap(~variable,scales = "free_x") + 
      geom_histogram(aes=(density))
      +title(sub = s, line = 5.5) 
      s<-summary(x1)

我还想将摘要数据附加到图中的每一列以进行一些分析。有替代方案吗?

谢谢。

据我所知,您无法为 facet_wrap 的子图添加字幕。您可以更改标题以适应您想要的内容。这是一个包含最小值、最大值、平均值和中值的示例:

data = data.frame(x1=rnorm(100),
                  x2=rnorm(100),
                  x3=rnorm(100),
                  x4=rnorm(100),
                  x5=rnorm(100),
                  x6=rnorm(100))


library(dplyr)
library(tidyr)
library(ggplot2)

x <- data %>% 
  gather(variable,value) %>%
  group_by(variable) %>%
  mutate(mean=mean(value),
            median=median(value),
            min=min(value),
            max=max(value),
            lab=paste(first(variable),"\nMin:",round(min,2),"Mean:",round(mean,2),"Median:",round(median,2),"Max:",round(max,2)))

ggplot(x,aes(x = value)) + 
  facet_wrap(~lab,scales = "free_x") + 
  geom_histogram(aes=(density)) +
  geom_vline(aes(x=mean))