Use colorBy
/fillBy
parameters and paint_a
/paint_b
/paint_c
aesthetics if you need to display two different layers with the same color aesthetic but different color scales.
Use new scale functions that allows to specify an aesthetic.
%useLatestDescriptors
%use lets-plot
LetsPlot.getInfo()
Lets-Plot Kotlin API v.4.3.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.3.1.0.
fun generateData(
p1: Number,
p2: Number,
p3: Number,
p4: Number,
p5: Number,
xMax: Int = 400,
yMax: Int = 300
): Map<String, List<*>> {
fun z_fun(x: Double, y: Double): Double {
var z = sin(x * p1.toDouble() * PI / xMax)
z += sin(y * p2.toDouble() * PI / yMax)
z += x * p3.toDouble() / xMax
z += y * p4.toDouble() / yMax
return z * p5.toDouble()
}
val x = ArrayList<Double>()
val y = ArrayList<Double>()
val z = ArrayList<Double>()
for (row in 0 until yMax) {
for (col in 0 until xMax) {
x.add(col.toDouble())
y.add(row.toDouble())
z.add(z_fun(col.toDouble(), row.toDouble()))
}
}
return mapOf("x" to x, "y" to y, "z" to z)
}
val heightData = generateData(3, 3, 3, 5, 11)
val temperatureData = generateData(1, 2, 5, 4, -0.5)
letsPlot() +
geomContour(data = heightData, bins = 15, size = 1) {
x = "x"; y = "y"; z = "z"; color = "..level.."
} +
geomContour(data = temperatureData, colorBy = "paint_a", bins = 8, size = 1) {
x = "x"; y = "y"; z = "z"; paint_a = "..level.."
} +
scaleColorGradient(name = "height", low = "#993404", high = "#ffffd4") +
scaleGradient("paint_a", name = "temperature", low = "#0571b0", high = "#ca0020") +
ggsize(800, 600)