Closed fbpyr closed 1 year ago
Well, for a start independent of the backend, the code you use in the example should error, as you cannot use both an x and y scale with geom_bar
(unless you use stat = "identity"
, in which case the y
values are simply read from that column, and no counting is done). So it's definitely an issue unrelated to this that the plot is just silently created and even uses the y label from the given y
. Need to make a fix for that.
What you probably intend though, is aes(x = "class", weight = "cyl", fill = "drv")
. That works correctly on the normal backend, but has the same issue using Vega. I'm looking into it, I think it should also be an easy fix.
Fixed in #160.
Thank you so much! Oh I see, I was still caught in altair syntax (where one would encode df column names to x and y).
When I use as you suggested:
import ggplotnim
let df = readCsv("mpg.csv")
ggplot(df, aes(x="class", weight="cyl", fill="drv")) +
geom_bar() +
scale_y_continuous() +
ggsave("rMpgStackedBarPlot.html")
I get:
but that seems to use count on the y-axis, instead of the weight/sum/accumulated cyl int?
(For cyl
I do get a warning saying cyl
is determined to be discrete,
but when I add the suggested scale_y_continuous
I still get the same warning.)
I would have expected weigth
would sum up the cyl
values
For example for minivan: 10 * 6cyl + 1 * 4cyl -> 64 cyl_count
,
so top of bar minivan
would be at 64 instead of 11?
Or would I need to pre-calculate it like in recipe rBarPlotCompStats
?
Ah, you're right of course. I didn't test it properly and just went by memory. weight
is currently only supported for regular histograms, but not bar charts. So one way is to precompute it and the other to let me fix it (hopefully quickly). :)
Ah ok - on histograms. Well, that would be amazing! - thank you so much @Vindaar
Coming up in #161 (and see the note about naming of the resulting y label).
Should be fine on the latest tag.
Wohoo - works like a charm! 🎇 😀 Thank you so much!!
..also works via vega: 😌
import ggplotnim
import ggplotnim/ggplot_vega
let df = readCsv("mpg.csv")
ggplot(df, aes(x="class", weight="cyl", fill="cyl")) +
geom_bar() +
ggvega("rMpgStackedBarPlot.html", show=false)
Using
rMpgStackedBarPlot
, when I specify the y-axis to becyl
(instead of y-axis being count without specification):I get a key error at L216 ggplotnim/ggplot_vega.nim :
so I added some echos before line 216 to understand what data was present and searched:
( I had a similar error in some of my graphs (x-axis[string] month names, y-axis[float] hours), but there it complained about missing key for the y-axis column name. So out of curiousity I renamed the y-axis key to
counts_GGPLOTNIM_INTERNAL
as it showed in the vega hover tools for only x-axis specified graphs, and the error went away! 😮 but it still just did the count of elements instead of the numeric values of the column. )Would there be a way to get the
cyl
column summend instead of the counts? @Vindaar : or is the above what you referred to as potential for larger backend changes?