%useLatestDescriptors
%use lets-plot
%use dataframe
LetsPlot.getInfo()
Lets-Plot Kotlin API v.4.7.2. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.3.2.
letsPlot() + geomLabel(x=0, y=0, label="Lorem ipsum", size=14) + ggsize(500, 200)
letsPlot() + geomLabel(
x = 0, y = 0,
label = "Lorem ipsum",
size = 14,
fill = "#edf8e9",
color = "#238b45",
fontface = "bold",
labelPadding = 1.0,
labelR = 0.5,
labelSize = 2.0
) + ggsize(500, 200)
val families = listOf(
"Arial",
"Calibri",
"Garamond",
"Geneva",
"Georgia",
"Helvetica",
"Lucida Grande",
"Rockwell",
"Times New Roman",
"Verdana",
"sans-serif",
"serif",
"monospace"
)
letsPlot() + geomLabel(size = 10, labelPadding = 0, labelR = 0) {
y = IntArray(families.size) { it };
label = families;
family = families
}
val justifications = listOf(0, 0.5, 1)
val angles = listOf(0, 45, 90)
val values = justifications.flatMap { hjust ->
justifications.flatMap { vjust ->
angles.map { angle ->
Triple(hjust, vjust, angle)
}
}
}
val data = mapOf(
"hjust" to values.map { it.first },
"vjust" to values.map { it.second },
"angle" to values.map { it.third }
)
letsPlot(data) { x = "hjust"; y = "vjust" } +
geomPoint(size = 3) +
geomLabel(label = "Text", size = 9) { hjust = "hjust"; vjust = "vjust"; angle = "angle" } +
facetGrid(y = "angle", yFormat = "{d}°") +
scaleXContinuous(breaks = listOf(0, 0.5, 1), expand = listOf(0.1)) +
scaleYContinuous(breaks = listOf(0, 0.5, 1), expand = listOf(0.0, 0.5)) +
themeClassic() + theme(panelBorder = elementRect(size = 1))
val mpg = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv")
mpg.head(3)
DataFrame: rowsCount = 3, columnsCount = 9
miles per gallon | number of cylinders | engine displacement (cu. inches) | engine horsepower | vehicle weight (lbs.) | time to accelerate (sec.) | model year | origin of car | vehicle name |
---|---|---|---|---|---|---|---|---|
18.000000 | 8 | 307.000000 | 130 | 3504 | 12.000000 | 70 | US | chevrolet chevelle malibu |
15.000000 | 8 | 350.000000 | 165 | 3693 | 11.500000 | 70 | US | buick skylark 320 |
18.000000 | 8 | 318.000000 | 150 | 3436 | 11.000000 | 70 | US | plymouth satellite |
val p = letsPlot(mpg.head(30).toMap()) {
x = "vehicle weight (lbs.)"
y = "miles per gallon"
label = "vehicle name"
}
p + geomLabel()
p + geomLabel(color = "white", fontface = "bold") {
fill = asDiscrete("number of cylinders", order = 1)
} + ggsize(800,400)
// Initialize Lets-Plot GeoTools extension.
%use lets-plot-gt(gt="[23,)")
@file:DependsOn("org.geotools:gt-shapefile:[23,)")
@file:DependsOn("org.geotools:gt-cql:[23,)")
import org.geotools.data.shapefile.ShapefileDataStoreFactory
import org.geotools.data.simple.SimpleFeatureCollection
import java.net.URL
import org.geotools.filter.text.cql2.CQL
val factory = ShapefileDataStoreFactory()
val worldFeatures : SimpleFeatureCollection = with("naturalearth_lowres") {
val url = "https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/shp/${this}/${this}.shp"
factory.createDataStore(URL(url)).featureSource.features
}
val europe = worldFeatures.subCollection(CQL.toFilter("continent = 'Europe'"))
val cityFeatures : SimpleFeatureCollection = with("naturalearth_cities") {
val url = "https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/shp/${this}/${this}.shp"
factory.createDataStore(URL(url)).featureSource.features
}
val cities = cityFeatures.toSpatialDataset()
letsPlot() +
geomMap(map = europe.toSpatialDataset(), fill="#e5f5e0") +
geomPoint(data = cities, color = "#224717", size = 3) +
geomLabel(data = cities, hjust = 0, vjust = 1, color = "#224717") { label = "name" } +
coordMap(xlim = -10.5 to 44.0, ylim = 36.0 to 60.5) +
theme(axis="blank", panelGrid="blank")