R-组合冲积图

时间:2018-08-23 18:05:30

标签: r data-visualization

我一直想知道如何使用R中的数据帧生成冲积图(例如,使用ggalluvial包)

我有如下数据框

   GENE UNTREATED TREATED
1    G1      FOUR    FOUR
2    G2      FOUR    FOUR
3    G3      FOUR    FOUR
4    G4      FOUR   THREE
5    G5     THREE    NONE
6    G6     THREE    NONE
7    G7       TWO   THREE
8    G8       TWO     ONE
9    G9       ONE     ONE
10  G10       TWO     ONE

我想用这些数据生成一个冲积图。例如,图中的2条柱将被未处理和已处理,并且连接将基于基因在治疗前后如何改变其值的比例。绝对有可能做到这一点,而我似乎并没有掌握冲积积积概念。任何帮助将不胜感激。

编辑:这是我制作的样例示例图

enter image description here

谢谢。

3 个答案:

答案 0 :(得分:2)

这似乎就是你所追求的

dd<-read.table(text="   GENE UNTREATED TREATED
1    G1      FOUR    FOUR
2    G2      FOUR    FOUR
3    G3      FOUR    FOUR
4    G4      FOUR   THREE
5    G5     THREE    NONE
6    G6     THREE    NONE
7    G7       TWO   THREE
8    G8       TWO     ONE
9    G9       ONE     ONE
10  G10       TWO     ONE", header=TRUE)

ggplot(dd, aes(axis1=UNTREATED, axis2=TREATED)) +
  geom_alluvium() + 
  geom_stratum(width = 1/12, fill = "black", color = "grey") +
  geom_label(stat = "stratum", label.strata = TRUE)

enter image description here

答案 1 :(得分:2)

或者,您可以使用ggalluvial随附的easyalluvial包装器

 dd<-read.table(text="   GENE UNTREATED TREATED
               1    G1      FOUR    FOUR
               2    G2      FOUR    FOUR
               3    G3      FOUR    FOUR
               4    G4      FOUR   THREE
               5    G5     THREE    NONE
               6    G6     THREE    NONE
               7    G7       TWO   THREE
               8    G8       TWO     ONE
               9    G9       ONE     ONE
               10  G10       TWO     ONE", header=TRUE)


easyalluvial::alluvial_wide( dd, id = GENE, fill_by = 'all_flows',
                             order_levels = c('NONE','FOUR', 'THREE', 'TWO', 'ONE'))

easyalluvial plot

答案 2 :(得分:1)

MrFlick的答案非常好。另一种选择是使用冲积图,这已在“ str.replace”中进行了讨论。

private void UserControl_Loaded( object sender, RoutedEventArgs e )
{
    DoubleAnimation doubleAnimation = new DoubleAnimation();
    doubleAnimation.From = -AdvMarquee.ActualHeight;
    doubleAnimation.To = 0;
    doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
    doubleAnimation.Duration = new Duration( TimeSpan.FromSeconds(5) );

    AdvMarquee.BeginAnimation( Canvas.TopProperty, doubleAnimation );

    // Dev Area
    List<String> Messages = new List<String>();

    Messages.Add( String.Format( "AdvMarquee : HasAnimatedProperties > " + AdvMarquee.HasAnimatedProperties ) );
    Messages.Add( String.Format( "doubleAnimation.From : " + doubleAnimation.From ) );
    Messages.Add( String.Format( "doubleAnimation.To : " + doubleAnimation.To ) );
    Messages.Add( String.Format( "doubleAnimation.RepeatBehavior : " + doubleAnimation.RepeatBehavior ) );
    Messages.Add( String.Format( "doubleAnimation.Duration : " + doubleAnimation.Duration ) );


    MessageBox.Show( String.Join("\n", Messages ) );
}

https://github.com/topepo/caret/issues/755

希望有帮助。

谢谢,山姆