R:我想针对所有其他数字列绘制一个分类列

R: I would like to plot one categorical column against all other numeric columns

我有一个数据集,其中第一列代表语言,其余列代表不同类别的使用百分比。first column repesent the language, the rest represent percentages of use

我想在一个图中表示这个 table。我认为堆叠条形图是最好的方法。在我看来,最好的方法是在 x 轴上表示列(lang 除外),在 y 轴上表示百分比,lang 作为填充。

要使用 ggplot2,您必须重新排列数据 int 'long' 格式,请参阅 ?melt

library(reshape2)
data2 <- melt(data)

下面将生成堆积条形图

library(ggplot2)
ggplot(data2, aes(variable, value, fill = Lang)) +
     geom_col()

编辑

关于您的错误:确保您使用的是最新版本的 ggplot2 - 我认为 geom_col 是最近添加的。

另一种方法是使用 geom_bar()

ggplot(data2, aes(variable, value, fill = Lang)) +
     geom_bar(stat = 'identity')

只是另一个选择,使用 tidyr 除了 reshape2

library(readr)
library(ggplot2)
library(tidyverse)

df <- read_delim("Lang  INT DIR ABS LND TOP VER IV  IR  REL
Arabic  39.05   5   0   3.33    44.76   9.76    11.9    11.43   24.29
Kiche   40.95   2.86    0   1.43    29.05   9.76    12.14   4.52    34.76
Spanish 20.45   2.25    2.86    2.04    33.74   13.7    12.07   9.41    40.08
Yucatec 39.56   6.63    13.27   7.86    49.63   11.3    16.46   15.48   25.31
Zapotec 24.79   0.43    51.28   1.07    32.26   9.83    8.76    8.33    4.06", delim = "\t")


df <- tidyr::gather(df, fields, value, -Lang)

ggplot(df, aes(x = fields, y = value, fill = Lang)) +
    geom_bar(stat = 'identity')