Search code examples
juliajulia-plotsdataframes.jl

Julia groupedDataFrame plot not showing in name


I am attempting to plot in julialang a single plot with groupedDataFrames ... which isn't working if I just pass the array of traces... but for now I am just trying to put the GroupKey as a string under the X-Axis of a single plot... but it just shows Trace0.. Any ideas?

using PlotlyJS, DataFrames, Tables

gdf=groupby(subset_df, :company_name)

trace_array = []

for key in keys(gdf)
    println(key)
    push!(trace_array, box(y=gdf[key].target_price, name=key))
end

plot(trace_array[2])

enter image description here

Also tried

    company_name_str = unique(gdf[key].company_name)
    println(company_name_str)
    push!(trace_array, box(y=gdf[key].target_price, name=company_name_str))

no change in behavior


Solution

  • I got your point. You're just missing an indexing in the optional name keyword argument: key[1]
    I created a synthetic dataframe to reproduce it for you:

    using PlotlyJS, DataFrames
    
    df = DataFrame(
      g=["group1", "group1", "group1", "group2", "group2"],
      x=[1, 2, 3, 1, 2],
    )
    
    gdf = groupby(df, :g)
    
    trace_array = []
    
    for key in keys(gdf)
        push!(trace_array, box(y=gdf[key].x, name=key[1]))
    end
    
    plot(trace_array[1])
    

    enter image description here

    As you can see, the group1 is shown on the x-axis.