sizeUnit
in Geoms geomPoint()
, geomText()
and geomLabel()
¶The sizeUnit
parameter relates the size of a geometry to the length of the unit step along one of the axes.
%useLatestDescriptors
%use lets-plot
LetsPlot.getInfo()
Lets-Plot Kotlin API v.4.7.1. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.3.1.
val size = 10
val data = mapOf(
"x" to listOf(0, 0, 0),
"y" to listOf(-size, 0, size),
"text" to listOf('A', 'b', '0')
)
fun title(geomName: String, sizeUnit: String? = null) = ggtitle("$geomName: size = $size, sizeUnit = ${sizeUnit ?: "default"}")
val p = letsPlot(data) { x = "x"; y = "y" } + scaleYContinuous(limits = -size to size, expand = listOf(0.15, 0))
gggrid(listOf(
p + geomPoint(size = size) + title("Point"),
p + geomPoint(size = size, sizeUnit ="y") + title("Point", "y")
))
gggrid(listOf(
p + geomText(size = size) { label = "text" } + title("Text"),
p + geomText(size = size, sizeUnit = "y") { label = "text" } + title("Text", "y"),
))
gggrid(listOf(
p + geomLabel(size = size) { label = "text" } + title("Label"),
p + geomLabel(size = size, sizeUnit = "y") { label = "text" } + title("Label", "y"),
))
val r = 0.5
val h = r * sqrt(3.0) / 2
val setsData = mapOf(
"x" to listOf(0, r, r / 2),
"y" to listOf(0, 0, h),
"size" to listOf(2 * r, 2 * r, 2 * r),
"color" to listOf("#e24462", "#306998", "#ffe873"),
)
val textsData = mapOf(
"x" to listOf(-r / 2, r + r / 2, r / 2, r / 2, -r / 8, r + r / 8, r / 2),
"y" to listOf(-r / 4, -r / 4, h + r / 2, -3 * r / 8, 5 * r / 8, 5 * r / 8, 5 * r / 16),
"text" to listOf("Kotlin", "Geospatial\nVisualization", "Grammar\nof\nGraphics", "ArcGIS", "Kandy", "ggmap", "Lets-Plot"),
"size" to List(7) { 0.4 * r }
)
letsPlot() +
geomPoint(data = setsData, sizeUnit = "x",
shape = 21, alpha = .5, color = "black",
tooltips = tooltipsNone) {
x = "x"; y = "y"; size = "size"; fill = "color"
} +
geomText(data = textsData, sizeUnit = "x") {
x = "x"; y = "y"; label = "text"; size = "size"
} +
scaleSizeIdentity() + scaleFillIdentity() +
xlim(-r to 2 * r) + ylim(-r to h + r) +
coordFixed() +
ggsize(600, 600) +
themeVoid()