breakWidth Parameter in Position Scales¶

The breakWidth parameter specifies a fixed distance between axis breaks.

If the scale has an associated transformation, the distance is measured in transformed units.
For example, on a log10 scale, breakWidth=1 places breaks at every power of 10, and breakWidth=0.5 — at every half-power.

In [1]:
%useLatestDescriptors
%use lets-plot
In [2]:
val csvUrl = "https://raw.githubusercontent.com/JetBrains/lets-plot-docs/refs/heads/master/data/diamonds.csv"
val text = java.net.URL(csvUrl).readText()
val lines = text.trim().split("\n")
val header = lines[0].split(",")
val caratIdx = header.indexOfFirst { it.trim('"') == "carat" }
val priceIdx = header.indexOfFirst { it.trim('"') == "price" }

val allRows = lines.drop(1).mapNotNull { line ->
    val cols = line.split(",")
    val c = cols.getOrNull(caratIdx)?.trim()?.toDoubleOrNull()
    val p = cols.getOrNull(priceIdx)?.trim()?.toDoubleOrNull()
    if (c != null && p != null) Pair(c, p) else null
}

val rand = java.util.Random(42)
val sample = allRows.shuffled(rand).take(5000)

val df = mapOf(
    "carat" to sample.map { it.first },
    "price" to sample.map { it.second }
)
println("Loaded ${sample.size} rows")
Loaded 5000 rows
In [3]:
// A log10 scale with auto-selected breaks
letsPlot(df) { x = "carat"; y = "price" } +
    geomPoint(alpha = 0.3) +
    scaleYLog10()
Out[3]:
0.5 1 1.5 2 2.5 3 3.5 4 398 631 1,000 1,585 2,512 3,981 6,310 10,000 15,849 price carat
In [4]:
letsPlot(df) { x = "carat"; y = "price" } +
    geomPoint(alpha = 0.3) +
    scaleYLog10(breakWidth = 0.5)   // breaks every 0.5 powers of 10
Out[4]:
0.5 1 1.5 2 2.5 3 3.5 4 1,000 3,162 10,000 price carat