【问题标题】:Visualizing feature distributions using ggplot2使用 ggplot2 可视化特征分布
【发布时间】:2016-11-11 23:03:48
【问题描述】:

我有一个包含两组的数据集。出于比较的目的,我想在同一个图上可视化每个组的特征值分布。这是当前表单中的数据框。

Group Feature  Frequency
A     Feature1 0.000221
B     Feature1 0.044112
A     Feature2 0.009346
B     Feature2 0.039939
A     Feature3 0.010597
B     Feature3 0.020723

我怎样才能重塑它,使每个特征都是一行,每个组是一列?以下是散点图所需的数据框。

Feature  FreqA     FreqB
Feature1 0.000221 0.044112
Feature2 0.009346 0.039939
Feature3 0.010597 0.020723

这个数据集有大约 100 个特征。

【问题讨论】:

  • ggplot(df, aes(x=write,y=read,colour=sex)+geom_point()
  • 这更多是 Stack Overflow 的问题,但我推荐 Hadley Wickham 的 tidyr 包。它具有spreadgather 之类的功能,用于执行此类操作。

标签: r data-visualization


【解决方案1】:
dfA <- df[df$Group == 'A',]
dfB <- df[df$Group == 'B',]

dfA$Group <- NULL
dfB$Group <- NULL

dfBoth <- merge(dfA,dfB, by="Feature")

【讨论】:

    【解决方案2】:

    如果你只是想绘制它,没有必要重塑数据。你可以这样做: ggplot(data,aes(Frequency)) + geom_density() + facet_wrap(~Feature)(或~Group,取决于你想要做什么)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-07
      • 2015-10-20
      • 1970-01-01
      • 2022-07-06
      • 1970-01-01
      • 2013-07-15
      相关资源
      最近更新 更多