简体   繁体   中英

how to change the order of categorical values on X-axis when using seaborn.FacetGrid?

I have following code:

g = sns.FacetGrid(correct_data, hue="congruency", col="PP", row="cue", height=4, ylim=(.4, .9))
g.map(sns.pointplot, "pattern", "RT")

This allows me to create a line plot per participant (PP) and cue (cue) showing separate lines for each level of congruency. Each line shows the relationship between pattern (X-axis) and reaction time (RT on the Y-axis). I would like the reverse the order of the categorical values on the X-axis, how can I do this? The "pattern"-variable has two levels, but I like to reverse the default order in which it is displayed.

Thank you.

You can pass the order= parameter (as well as hue_order= ) to sns.pointplot() inside the call to g.map() to choose the order of the categorical variable

att = sns.load_dataset("attention")
g = sns.FacetGrid(att, col="subject", col_wrap=5, height=1.5)
g = g.map(sns.pointplot, "solutions", "score", order=[3,1,2])

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM