JetBrains / lets-plot-kotlin

Grammar of Graphics for Kotlin
https://lets-plot.org/kotlin/
MIT License
422 stars 36 forks source link

incorrect legend #104

Closed mizraelson closed 4 months ago

mizraelson commented 2 years ago

I have plotted a deprogram by combining geomSegment() and geomPoint(). When I apply color schemes to each function, I get a joined legend which I would want to be separated.

image

In the picture above I want to have different legends for "sex" and "age", not joined together.

Here is the part of code that creates a deprogram plot:

`operator fun Plot.plus(dendro: GeomDendroLayer) = run {

this + geomSegment(dendro.edgesData) {
    x = "x1"
    y = "y1"
    xend = "x2"
    yend = "y2"
    linetype = dendro.ops.edgeLinetype
    color = dendro.ops.edgeColor
} + geomPoint(
    dendro.pointsData
) {
    x = "x"
    y = "y"
    shape = dendro.ops.nodeShape
    color = dendro.ops.nodeColor
}

}

var plot = letsPlot() plot += geomDendro(tree, connectionType = ConnectionType.rectangle, edgeMetaInheritance = EdgeMetaInheritance.up){ nodeColor = "age" edgeColor = "sex" } `

alshan commented 2 years ago

Hi, there can not be >1 legends for a single aesthetic (i.e. "color"). In the case of segments and points the workaround would be to use the "fill" aesthetic for the points layer. For that to work you will need to use a 'fillable' shape for points, like shape 19 or 21.

image

mizraelson commented 2 years ago

I tried that, but I get a weird result:

image

`operator fun Plot.plus(dendro: GeomDendroLayer) = run {

this +
        geomSegment(dendro.edgesData) {
    x = "x1"
    y = "y1"
    xend = "x2"
    yend = "y2"
    linetype = dendro.ops.edgeLinetype
    color = dendro.ops.edgeColor
}+
        geomPoint(
    dendro.pointsData, shape = 19
) {
    x = "x"
    y = "y"
    fill = dendro.ops.nodeColor
}

}`

alshan commented 2 years ago

Oh, sorry, shape 19 wont work, try shape 21.

mizraelson commented 2 years ago

Oh, sorry, shape 19 wont work, try shape 21.

image

Is there a way to use the same color for a counter or make it blank so its a solid circle?

alshan commented 2 years ago

Transparent color = "rgba(0, 0, 0, 0)" might work. May be size = 0 also but not sure. Upd: size - certainly not.

alshan commented 4 months ago

UPD: