Hi, When I use ggpubr with an x-axis utilizing descriptive categories (eg. bar chart for different colors of car), it sorts all of the labels alphabetically. Is there a way to change this so it shows in the order I want? Thanks, April [[alternative HTML version deleted]]
Patrick (Malone Quantitative)
2019-Oct-26 13:08 UTC
[R] ggpubr: order of non-numeric x-axis items
Try using relevel() to organize the categories in your factor in the desired order. You may need to use relevel(as.factor()) . On Sat, Oct 26, 2019 at 6:51 AM April Ettington <aprilettington at gmail.com> wrote:> > Hi, > > When I use ggpubr with an x-axis utilizing descriptive categories (eg. bar > chart for different colors of car), it sorts all of the labels > alphabetically. Is there a way to change this so it shows in the order I > want? > > Thanks, > > April > > [[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.
No. relevel() only changes the order in one specific way. Use `levels<-`() to reorder in a general way:> z <- factor(rep(letters[3:1],2)) > z[1] c b a c b a Levels: a b c> z <-relevel(z, ref = "c") > z[1] c b a c b a Levels: c a b> levels(z)<- c("c","b","a") > z[1] c a b c a b Levels: c b a 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 Sat, Oct 26, 2019 at 6:09 AM Patrick (Malone Quantitative) < malone at malonequantitative.com> wrote:> Try using relevel() to organize the categories in your factor in the > desired order. You may need to use relevel(as.factor()) . > > On Sat, Oct 26, 2019 at 6:51 AM April Ettington > <aprilettington at gmail.com> wrote: > > > > Hi, > > > > When I use ggpubr with an x-axis utilizing descriptive categories (eg. > bar > > chart for different colors of car), it sorts all of the labels > > alphabetically. Is there a way to change this so it shows in the order I > > want? > > > > Thanks, > > > > April > > > > [[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. >[[alternative HTML version deleted]]