I have created a DataFrame such as
│ Row │ Gender_Code │ N │
│ │ String │ Int64 │
├─────┼─────────────┼───────┤
│ 1 │ M │ 1789 │
│ 2 │ F │ 205 │
When I applied on it Geom.bar, the bars don’t have the frequency of the M vs F.
How to add count legend on Bar graph.
See the Stat.dodge example in the Gadfly docs.
If I have
│ Row │ Age │ N │
│ │ Int64 │ Int64 │
├─────┼───────┼───────┤
│ 1 │ 46 │ 3 │
│ 2 │ 45 │ 58 │
│ 3 │ 44 │ 86 │
│ 4 │ 43 │ 131 │
then my command of
num_age_sorted_byFrequency.label = string.(round.(Int, num_age_sorted_byFrequency.N))
Age_Frequency_barplot = plot(num_age_sorted_byFrequency, x=:Age, y=:N, label=:label, Geom.label(position=:centered), Stat.dodge(position=:stack), Geom.bar(position=:stack))
works
But when I have a
│ Row │ Gender_Code │ N │
│ │ String │ Int64 │
├─────┼─────────────┼───────┤
│ 1 │ M │ 1789 │
│ 2 │ F │ 205 │
and I apply
num_Gender_Code_sorted_byFrequency.label = string.(round.(Int, num_Gender_Code_sorted_byFrequency.N))
Gender_Code_Frequency_barplot = plot(num_Gender_Code_sorted_byFrequency, x=:Gender_Code, y=:N, label=:label, Geom.label(position=:centered), Stat.dodge(position=:stack), Geom.bar(position=:stack))
I get
Error showing value of type Plot:
ERROR: MethodError: no method matching -(::String, ::String)
Ok, I see now. In this example with Geom.bar
, Stat.dodge
isn’t needed:
plot(df, x=:Gender_Code, y=:N, Geom.bar, label=string.(df.N),
Geom.label(position=:above))
With Stat.dodge
, for some reason it’s necessary to add Scale.x_discrete
:
plot(df, x=:Gender_Code, y=:N, label=string.(df.N),
Geom.label(position=:above), Stat.dodge, Geom.bar,
Scale.x_discrete)
and I should investigate why!