1

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

Erik
  • 2,782
  • 3
  • 34
  • 64
  • You haven't provided a minimal reproducible code and I really do not understand what is your exact expected output. – Shayan Dec 27 '22 at 14:54
  • `name="blahblahblah"` properly sets the X-axis legend in the plot ... instead of `trace 0` like in this photo provided... When I attempt to use `GroupKey` .. as the X-Axis label as seen in the example code.. it doesn't work. I will append some dummy code to create a dummy groupedDataFrame asap.. – Erik Dec 27 '22 at 15:03

1 Answers1

2

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.

Shayan
  • 5,165
  • 4
  • 16
  • 45