Hello, I am trying to figure out if there is a way to order the left side of a Sankey diagram from most frequent to least frequent. I am using R version 3.2.1 and using googleVis version 0.5.9 for the Sankey. I've tried sorting, but that does not work. Is there anyway to force it to arrange the left ("before") side in decreasing frequency? Something I am missing? Does not have to be using googleVis. Thank you! -Angela Example of the data I have, in a csv file: before??? after A??? B A??? B A??? B A??? C A??? A A??? A A??? B D??? E F??? B F??? B F??? F G??? H G??? A I reformat the data in R so it looks like this: before??? after??? count A??? B??? 4 A??? C??? 1 A??? A??? 2 D??? E??? 1 F??? B??? 2 F??? F??? 1 G??? H??? 1 G??? A??? 1 Then plot using this: plot( gvisSankey (data, from="before", to="after", weight="freq", options=list(width=600, height=800, ??? sankey="{iterations: 2}")))
Hi Angela, Assuming that your reformatted data is named "data", have you tried: data[order(data$count,data$before,decreasing=TRUE),] Jim On Thu, Jul 23, 2015 at 3:15 AM, Angela via R-help <r-help at r-project.org> wrote:> Hello, > > I am trying to figure out if there is a way to order the left side of a Sankey diagram from most frequent to least frequent. I am using R version 3.2.1 and using googleVis version 0.5.9 for the Sankey. I've tried sorting, but that does not work. Is there anyway to force it to arrange the left ("before") side in decreasing frequency? Something I am missing? Does not have to be using googleVis. Thank you! > > -Angela > > Example of the data I have, in a csv file: > > before after > A B > A B > A B > A C > A A > A A > A B > D E > F B > F B > F F > G H > G A > > I reformat the data in R so it looks like this: > > before after count > A B 4 > A C 1 > A A 2 > D E 1 > F B 2 > F F 1 > G H 1 > G A 1 > > Then plot using this: > plot( gvisSankey (data, from="before", to="after", weight="freq", options=list(width=600, height=800, > sankey="{iterations: 2}"))) > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi Jim, I tried it and it while it does make the diagram look more like what I want, there are a few categories still out of order. Thank you for your help! -Angela -------------------------------------------- On Thu, 7/23/15, Jim Lemon <drjimlemon at gmail.com> wrote: Subject: Re: [R] Ordering in Sankey diagram using R and googleVis Cc: "r-help mailing list" <r-help at r-project.org> Date: Thursday, July 23, 2015, 6:43 AM Hi Angela, Assuming that your reformatted data is named "data", have you tried: data[order(data$count,data$before,decreasing=TRUE),] Jim On Thu, Jul 23, 2015 at 3:15 AM, Angela via R-help <r-help at r-project.org> wrote: > Hello, > > I am trying to figure out if there is a way to order the left side of a Sankey diagram from most frequent to least frequent. I am using R version 3.2.1 and using googleVis version 0.5.9 for the Sankey. I've tried sorting, but that does not work. Is there anyway to force it to arrange the left ("before") side in decreasing frequency? Something I am missing? Does not have to be using [[elided Yahoo spam]] > > -Angela > > Example of the data I have, in a csv file: > > before? ? after > A? ? B > A? ? B > A? ? B > A? ? C > A? ? A > A? ? A > A? ? B > D? ? E > F? ? B > F? ? B > F? ? F > G? ? H > G? ? A > > I reformat the data in R so it looks like this: > > before? ? after? ? count > A? ? B? ? 4 > A? ? C? ? 1 > A? ? A? ? 2 > D? ? E? ? 1 > F? ? B? ? 2 > F? ? F? ? 1 > G? ? H? ? 1 > G? ? A? ? 1 > > Then plot using this: > plot( gvisSankey (data, from="before", to="after", weight="freq", options=list(width=600, height=800, >? ???sankey="{iterations: 2}"))) > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.