Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "label" as a prefix when printing from dataframes using "group" #700

Closed
sylvaticus opened this issue Feb 23, 2017 · 4 comments
Closed

Comments

@sylvaticus
Copy link

sylvaticus commented Feb 23, 2017

Consider the following example:

using DataFrames, Plots, StatPlots
df = DataFrame(
  product = ["orange","orange","orange","orange","banana","banana","banana","banana"],
  year = [2010,2011,2012,2013,2010,2011,2012,2013],
  prod = [120,150,170,160,100,130,165,158],
  cons = [70,90,100,95,   80,95,110,120]
)
plotlyjs() 
mycolors = [:blue, :red ]
fruits_plot = plot(df, :year, :prod, group=:product, linestyle = :solid, linewidth=3, linecolor=:match, color_palette = mycolors)
fruits_plot = plot!(df, :year, :cons, group=:product, linestyle = :dot, linewidth=3, linecolor=:match, color_palette = mycolors)

This print (forget here the colour issue):

fruits_plot

It would be nice to have the possibility to label the first group of series differently than the second one, while still retaining the individual serie label.
If I add to the first group of series label="Production of " or to the second one label="Consumption of " this will be substituted to the one coming from the dataframe using group.
This proposal is to consider label as a prefix and concatenate it with the label coming from the dataframe when group is used.
Alternatively a label_suffix and/or a label_postfix attribute could be introduced.

@mkborregaard
Copy link
Member

I can see how it's helpful in the current example, but not that it is a general functionality we need. It would be nice with a general design for how legends should work that considers all the possibilities, but this does not seem generally useful.

In the current example, you can just do label = ("Production of " * sort(unique(df[:product]))') to get the behaviour you want.

@sylvaticus
Copy link
Author

Hello, in Julia 0.6 this workaround doesn't work any more.. nor using reshape(sort(unique(df[:product])), (1, :)) works, as the object produced
(1×2 Base.ReshapedArray{String,2,DataArrays.DataArray{String,1},Tuple{}}) is not the one expected by plots..

@daschw
Copy link
Member

daschw commented Jul 19, 2017

label = "Production of " .* reshape(sort(unique(df[:product])), (1, :)) works for me.

@sylvaticus
Copy link
Author

yep that works, thank you..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants