StatsPlots.jl
StatsPlots.jl copied to clipboard
Hidden sorting error when using a scatter over a String type Xaxis
I have a Dataframe with 1 row for each value of a categorical variable (stored as a string type). In another column, multiple values are stored in a vector. my goal is to have the categorical variable on the axis and a scatter for each value. This is easily done, but to be consistent across visualizations I want to be able to sort the axis and I use a dummy variable to sort! the Dataframe in place. The result is quite puzzling, the labels on the x-axis change according to my new sorting but the values are plotted as it was originally. I checked the content of the Dataframe after sorting using BrowseTables and the values column is correctly resort but the plot doesn't. I produce a small example and took a screenshot
example = DataFrame()
example[!,:Cat] = ["A","B","C"]
example[!,:Vals] = [rand(5) for x in example.Cat]
example[!,:Position] = [3,1,2]
p1 = @df example scatter(:Cat, :Vals, markercolor = :grey, label = false)
sort!(example,:Position)
p2 = @df example scatter(:Cat, :Vals, markercolor = :blue, label = false)
plot(p1,p2)
my status is [5f4fecfd] BrowseTables v0.3.0 [336ed68f] CSV v0.6.2 [5ae59095] Colors v0.12.0 [a93c6f00] DataFrames v0.21.0 [31c24e10] Distributions v0.23.2 [38e38edf] GLM v1.3.9 [09f84164] HypothesisTests v0.10.0 [5ab0869b] KernelDensity v0.5.1 [189a3867] Reexport v0.2.0 [2913bbd2] StatsBase v0.33.0 [f3b207a7] StatsPlots v0.14.6