2

I've written a plot in Kotlin using https://github.com/JetBrains/lets-plot library. I want to be able to set a title, a subtitle, a caption, and edit (or remove) the legend title.

    val goodColors = listOf("#A1DBB2", "#69D2E7")
    val badColors = listOf("#F45D4C", "#F7A541", "#FACA66", "#F45D4C", "#F7A541", "#FACA66")

    val barWidth = 0.4

    return letsPlot() +
            labs(x = "", y = "", title = "My title") +

            geomBar(stat = Stat.identity, position = Pos.stack, color = "black", width = barWidth) {
                x = listOf(1.0, 1.0, 2.0, 2.0).map { it - (barWidth / 2) + barWidth }
                y = listOf(16, 34, 18, 37)
                fill = listOf("Good one", "Good two", "Good one", "Good two")
            } +

            geomBar(stat = Stat.identity, position = Pos.stack, color = "red", width = barWidth) {
                x = listOf(1.0, 1.0, 1.0, 2.0, 2.0, 2.0).map { it - (barWidth / 2) }
                y = listOf(71, 20, 17, 55, 11, 10)
                fill = listOf("Bad one", "Bad two", "Bad Three", "Bad one", "Bad two", "Bad Three")
            } +

            scaleFillManual(values = goodColors + badColors) +
            scaleXDiscrete(breaks = listOf(1.0, 2.0), labels = listOf("2021-01-01", "2021-02-01")) +
            theme()

In ggplot2, I can set the subtitle in labs(), ggtitle() or theme(), but in Lets-plot, these functions don't accept either a subtitle or a caption.

Is there a way to set a subtitle, a caption, and edit or remove the legend title?

Sample output from code above

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Niels
  • 9,264
  • 4
  • 29
  • 26

1 Answers1

1

Try to remove the legend title by setting an empty name for fill scale:

+ scale_fill_discrete(name="")

The situation with subtitle and caption is bad, please follow #417.

UPD: subtitle & caption were added in v2.3.0.

alshan
  • 136
  • 3
  • `name=""` actually removes the entire legend. `scaleFillDiscrete(name=" ", labels = labels) +` did the trick for me. – Niels Aug 08 '21 at 22:14