在每列中创建2个数量的条形图

时间:2015-05-17 20:09:44

标签: r graph bar-chart multiple-columns

我想使用以下信息创建条形图。我希望它分为顶行和缺席/现在。我已经尝试了条形图和ggplot,但是他们提出了错误或不正确的信息。谢谢!

    LHUM    RHUM    LRAD    RRAD    LFEM    RFEM    LTIB    RTIB
    present absent  present absent  present present absent  present
    present present absent  present present present present present
    present present present present present present present present
    present present present present present present present present
    present present present present present present present present
    present present present present present present present present
    present present present absent  present present present present
    present present absent  present present present present present
    present present absent  present present present present present
    present present present absent  present present present present
    present present present absent  present present present present
    present absent  present absent  present present present present
    present present present absent  present present present present
    present present present present present absent  present absent

1 个答案:

答案 0 :(得分:1)

从你的问题来看,我并不是100%确定你想要什么。也许这个 - 假设您的数据位于名为df

的数据框中

首先使用tidyr将其重塑为ggplot longform格式。然后绘制......

library(dplyr)
library(tidyr)
df <- df %>% gather(name,value,1:8)

library(ggplot2)
ggplot(df, aes(name, color=value, fill=value)) + geom_bar()

enter image description here