简体   繁体   English

如何使用 Julia 包 Gadfly 在箱线图中对分类变量进行排序

[英]How to order a categorical variable in a boxplot using the Julia package Gadfly

Gadfly does not seem to use the (level) order of categorical variables: Gadfly 似乎没有使用分类变量的(级别)顺序:

using CSV
using DataFrames
using Gadfly
using HTTP

url = "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv"

tips = CSV.File(HTTP.get(url).body) |> DataFrame
categorical!(tips, :day)
ordered!(tips.day, true)
levels!(tips.day, ["Thur", "Fri", "Sat", "Sun"])

Gadfly.plot(tips, x=:day, y=:total_bill, color=:smoker, Geom.boxplot)

在此处输入图片说明

Should the plot not inherit the order specified in the categorical variable?绘图不应该继承分类变量中指定的顺序吗?

I found a way to order the categorical values, but that feels a little 'buggy' because of specifying the order again.我找到了一种对分类值进行排序的方法,但由于再次指定顺序,感觉有点“错误”。

Gadfly.plot(tips, x=:day, y=:total_bill, color=:smoker, Geom.boxplot,
    Scale.x_discrete(levels=levels(tips.day)))

在此处输入图片说明

Any suggestions how to solve this?任何建议如何解决这个问题?

In Gadfly, for discrete x the order of the values is determined by their order in the dataframe (so currently the level order in the CategoricalArray is not supported).在 Gadfly 中,对于离散x ,值的顺序由它们在数据帧中的顺序决定(因此目前不支持 CategoricalArray 中的级别顺序)。 It might not be supported in the future, because DataFrames plans to drop CategoricalArrays ( https://github.com/JuliaData/DataFrames.jl/issues/2321 ).将来可能不支持它,因为 DataFrames 计划放弃 CategoricalArrays ( https://github.com/JuliaData/DataFrames.jl/issues/2321 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 matplotlib 绘图时如何订购分类月份变量? - How to order categorical month variable when plotting using matplotlib? 如何使用R检查变量是否分类? - How to check if a variable is categorical with R? 如何基于数值变量创建分类变量 - How to create categorical variable based on a numerical variable 如何使用grep或grepl在数据框中创建新变量以简化分类变量中的级别 - How to create a new variable in a data frame using grep or grepl to simplify levels in a categorical variable 如何折叠 R 中分类变量的水平 - How to collapse levels in a categorical variable in R 如何按 pyspark 中的有序分类变量创建和排序 - how to create & sort by an ordered categorical variable in pyspark R - 如何转换频率中的分类变量 - R - How to convert a categorical variable in frequencies 我需要使用 pandas dataframe 根据第二个分类变量中的值来估算分类变量的缺失值 - I need to impute the missing values of a categorical variable based on the values in second categorical variable using pandas dataframe 使用 DataFramesMeta 包中的 @linq 整理 Julia 中的数据 - Tidying data in Julia using @linq from the DataFramesMeta package 如何使用 ifelse 条件数据框在 Julia 中创建新变量? - How can I create a new variable in Julia using an ifelse condition dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM