another, hopefully simple one -- is there a way to...
# datascience
g
another, hopefully simple one -- is there a way to combine color and type (for example) in the legends? Currently for a line graph if i do
Copy code
color("Metric")
            type( "Metric")
... i get 2 separate legends, one showing colours and the other line types (in this particular case, "Metric" only ever has 2 values, and in reality, i use
categorical
to determine which one gets a dashed line, whereas i currently keep the default colour mappings... while i can turn off the legend for line types, the one remaining for colours is useful, but looks wrong since the "blue" line appears solid in the legend)
a
Hi! Could you please share your code? This should work by default:
g
thanks @Andrei Kislitsyn -- here's what i currently do
Copy code
val dirPlot = allData
    .select("Period", "Unfiltered", "Filtered")
    .gather("Unfiltered", "Filtered").into("Metric", "Value")
    .plot {
        layoutWithHorizontalTopLeftLegend("My title")()
        line {
            x("Period"){
                axis.name = ""
            }
            y("Value") {
                axis.name = "%"
                scale = continuous(0..100)
            }
            color("Metric") {
                legend.name = "" // The legend title is the column name by default, which isn't useful here ("Metric")
            }
            type( "Metric") {
                scale = categorical("Unfiltered" to LineType.DASHED, "Filtered" to LineType.SOLID)
                legend {
                    type = LegendType.None
                }
            }
            tooltips(enable = true)
        }
    }
right, so i remove legend.name from color{}, then it works as your example, but i can't see how/where to remove the legend title
a
Looks like you need to remove legend name for both aesthetics:
Try this instead of not displaying
type
legend.
g
ha that works perfectly, thanks
i accidentally just found out I can also do
Copy code
layout {
        style {
            legend {
                title {
                    blank = true
...
which leaves the plots a little cleaner (i'm reusing a function for layouts across several plots) but of course only makes sense if i can dispense of all legend titles in the given plot
the next thing i'd love for legends is the ability to have no background (or transparent with an alpha level) -- or better yet, have a "smart" positioning system that positions the legend wherever it doesn't overlap with the plot (of course i could also just leave them outside the plot but i'm tight on space so i'd rather maximise the space used by the plot itself)
a
That's a nice feature indeed!
I will ask Lets-Plot team about it!
👍 1