Hi, I have the following problem: I want to visualize distributions of a few varibles in a specific order with a help of tree figure. Above of all is "Action x" and that happens for two (or n) reasons: "Reason 1" 50 % and "Reason 2" 50 %. Further, "Reason 1" happens for two (or n) subreasons: "Subreason 11" (75 %) and "Subreason 12" (25 %). And further, "Subreason 11" happens for two (or n) subsubreason "SubSubreason 111" etc. Every time when parent node splits to its childs, the sum of child node's percentages should be 100 %. I am very pleaseful if someone could help me with this! If the plot cannot be made "on the fly", also instructions of custom tree helps (hard coded values). Here is the test data: Level_0 = c("Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X") Level_1 = c("Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2") Level_2 = c("Subreason 11", "Subreason 11", "Subreason 11", "Subreason 11", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 22", "Subreason 22") Level_3 = c("Subsubreason 111", "Subsubreason 111", "Subsubreason 111", "Subsubreason 112", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 222", "Subsubreason 222") Levels = data.frame(Level_0 = Level_0, Level_1 = Level_1, Level_2 = Level_2, Level_3 = Level_3) Best regards, Joonas Isoketo [[alternative HTML version deleted]]
I am not really sure what you want, but it sounds like you want the "rpart" package (which is part of the standard R distribution). If that won't do, check the machine learning task view here: https://cran.r-project.org/web/views/MachineLearning.html Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Jun 8, 2016 at 11:31 AM, Joonas Isoketo <joonas.isoketo at houston-analytics.com> wrote:> Hi, > > I have the following problem: > > I want to visualize distributions of a few varibles in a specific order with a help of tree figure. Above of all is "Action x" and that happens for two (or n) reasons: "Reason 1" 50 % and "Reason 2" 50 %. > Further, "Reason 1" happens for two (or n) subreasons: "Subreason 11" (75 %) and "Subreason 12" (25 %). And further, "Subreason 11" happens for two (or n) subsubreason "SubSubreason 111" etc. > > Every time when parent node splits to its childs, the sum of child node's percentages should be 100 %. > > I am very pleaseful if someone could help me with this! If the plot cannot be made "on the fly", also instructions of custom tree helps (hard coded values). > > Here is the test data: > > Level_0 = c("Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X") > Level_1 = c("Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2") > Level_2 = c("Subreason 11", "Subreason 11", "Subreason 11", "Subreason 11", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 22", "Subreason 22") > Level_3 = c("Subsubreason 111", "Subsubreason 111", "Subsubreason 111", "Subsubreason 112", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 222", "Subsubreason 222") > > Levels = data.frame(Level_0 = Level_0, Level_1 = Level_1, Level_2 = Level_2, Level_3 = Level_3) > > > > Best regards, > > Joonas Isoketo > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
> On Jun 8, 2016, at 1:03 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote: > > I am not really sure what you want, but it sounds like you want the > "rpart" package (which is part of the standard R distribution).I?m not sure either, but do you want to fit a model (in which case Bert?s suggestion of ?rpart? is on target), or just visualize an existing tree structure? In the latter case presentation software may be the best option.> > If that won't do, check the machine learning task view here: > https://cran.r-project.org/web/views/MachineLearning.html > > Cheers, > Bert > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Wed, Jun 8, 2016 at 11:31 AM, Joonas Isoketo > <joonas.isoketo at houston-analytics.com> wrote: >> Hi, >> >> I have the following problem: >> >> I want to visualize distributions of a few varibles in a specific order with a help of tree figure. Above of all is "Action x" and that happens for two (or n) reasons: "Reason 1" 50 % and "Reason 2" 50 %. >> Further, "Reason 1" happens for two (or n) subreasons: "Subreason 11" (75 %) and "Subreason 12" (25 %). And further, "Subreason 11" happens for two (or n) subsubreason "SubSubreason 111" etc. >> >> Every time when parent node splits to its childs, the sum of child node's percentages should be 100 %. >> >> I am very pleaseful if someone could help me with this! If the plot cannot be made "on the fly", also instructions of custom tree helps (hard coded values). >> >> Here is the test data: >> >> Level_0 = c("Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X") >> Level_1 = c("Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2") >> Level_2 = c("Subreason 11", "Subreason 11", "Subreason 11", "Subreason 11", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 22", "Subreason 22") >> Level_3 = c("Subsubreason 111", "Subsubreason 111", "Subsubreason 111", "Subsubreason 112", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 222", "Subsubreason 222") >> >> Levels = data.frame(Level_0 = Level_0, Level_1 = Level_1, Level_2 = Level_2, Level_3 = Level_3) >> >> >> >> Best regards, >> >> Joonas Isoketo >> >> >> >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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. > > ______________________________________________ > 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 Joonas, It is easy to display hierarchic classification using either the plot.dendrite or sizetree functions (plotrix). At the moment, they will only display counts, not percentages. It would not be too difficult to reprogram either one to display percentages. Here are examples with shortened category names (you'll see why): Level_0 = c("Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X") Level_1 = c("R1", "R1", "R1", "R1", "R1", "R1", "R1", "R1", "R1", "R1", "R2", "R2", "R2", "R2", "R2", "R2", "R2", "R2", "R2", "R2") Level_2 = c("Subr11", "Subr11", "Subr11", "Subr11", "Subr12", "Subr12", "Subr12", "Subr12", "Subr12", "Subr12", "Subr21", "Subr21", "Subr21", "Subr21", "Subr21", "Subr21", "Subr21", "Subr21", "Subr22", "Subr22") Level_3 = c("Subsubr111", "Subsubr111", "Subsubr111", "Subsubr112", "Subsubr121", "Subsubr121", "Subsubr121", "Subsubr121", "Subsubr121", "Subsubr121", "Subsubr221", "Subsubr221", "Subsubr221", "Subsubr221", "Subsubr221", "Subsubr221", "Subsubr221", "Subsubr221", "Subsubr222", "Subsubr222") Levels = data.frame(Level_0 = Level_0, Level_1 = Level_1, Level_2 Level_2, Level_3 = Level_3) library(plotrix) plot.dendrite(Levels) sizetree(Levels) Jim On Thu, Jun 9, 2016 at 6:03 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote:> I am not really sure what you want, but it sounds like you want the > "rpart" package (which is part of the standard R distribution). > > If that won't do, check the machine learning task view here: > https://cran.r-project.org/web/views/MachineLearning.html > > Cheers, > Bert > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Wed, Jun 8, 2016 at 11:31 AM, Joonas Isoketo > <joonas.isoketo at houston-analytics.com> wrote: >> Hi, >> >> I have the following problem: >> >> I want to visualize distributions of a few varibles in a specific order with a help of tree figure. Above of all is "Action x" and that happens for two (or n) reasons: "Reason 1" 50 % and "Reason 2" 50 %. >> Further, "Reason 1" happens for two (or n) subreasons: "Subreason 11" (75 %) and "Subreason 12" (25 %). And further, "Subreason 11" happens for two (or n) subsubreason "SubSubreason 111" etc. >> >> Every time when parent node splits to its childs, the sum of child node's percentages should be 100 %. >> >> I am very pleaseful if someone could help me with this! If the plot cannot be made "on the fly", also instructions of custom tree helps (hard coded values). >> >> Here is the test data: >> >> Level_0 = c("Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X", "Action X") >> Level_1 = c("Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 1", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2", "Reason 2") >> Level_2 = c("Subreason 11", "Subreason 11", "Subreason 11", "Subreason 11", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 12", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 21", "Subreason 22", "Subreason 22") >> Level_3 = c("Subsubreason 111", "Subsubreason 111", "Subsubreason 111", "Subsubreason 112", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 121", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 221", "Subsubreason 222", "Subsubreason 222") >> >> Levels = data.frame(Level_0 = Level_0, Level_1 = Level_1, Level_2 = Level_2, Level_3 = Level_3) >> >> >> >> Best regards, >> >> Joonas Isoketo >> >> >> >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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. > > ______________________________________________ > 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.