%useLatestDescriptors %use lets-plot %use dataframe LetsPlot.getInfo() var mpg_df = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv") mpg_df.head() val mpg_dat = mpg_df.toMap() val p = letsPlot(mpg_dat) {x="displ"; y="cty"} + scaleSize(range = 5 to 15, breaks = listOf(15, 40)) + ggsize(600, 350) p + geomPoint(shape=21, color="white", tooltips=layerTooltips() .line("@manufacturer \n@model") .line("@|@class") .line("@|@year")) {fill="drv"; size="hwy"} // Use '\n' in 'format' p + geomPoint(shape=21, color="white", tooltips=layerTooltips().format("^size", "{.0f} \n(mpg)")) {fill="drv"; size="hwy"} // Add title to default tooltip lines p + geomPoint(shape=21, color="white", tooltips=layerTooltips().title("@manufacturer @model")) {fill="drv"; size="hwy"} // Add title to user specified multiline tooltip p + geomPoint(shape=21, color="white", tooltips=layerTooltips("class", "year").title("@manufacturer @model") ) {fill="drv"; size="hwy"} // Multi-line title p + geomPoint(shape=21, color="white", tooltips=layerTooltips() .title("Car info: \n@manufacturer @model") .line("@|@class") .line("drive train|@drv") .line("@|@year")) {fill="drv"; size="hwy"} // 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 } // Convert Feature Collection to SpatialDataset. // Use 10 decimals to encode floating point numbers (this is the default). val world = worldFeatures.toSpatialDataset(10) // Add long descriptions val dataWithDescr = mapOf( "region" to listOf("Europe", "Asia", "North America", "Africa", "Australia", "Oceania"), "description" to listOf( "A continent located entirely in the Northern Hemisphere and mostly in the Eastern Hemisphere. It shares the continental landmass of Afro-Eurasia with both Asia and Africa. It is bordered by the Arctic Ocean to the north, the Atlantic Ocean to the west, the Mediterranean Sea to the south and Asia to the east.", "Earth's largest and most populous continent. It shares the continental landmass of Eurasia with the continent of Europe, and the continental landmass of Afro-Eurasia with Africa and Europe. Asia covers an area of 44,579,000 square kilometres, about 30% of Earth's total land area and 8.7% of the Earth's total surface area.", "A continent in the Northern Hemisphere and almost entirely within the Western Hemisphere. It is bordered to the north by the Arctic Ocean, to the east by the Atlantic Ocean, to the southeast by South America and the Caribbean Sea, and to the west and south by the Pacific Ocean.", "The world's second-largest and second-most populous continent, after Asia in both cases. At about 30.3 million km2 including adjacent islands, it covers 6% of Earth's total surface area and 20% of its land area. With 1.3 billion people as of 2018, it accounts for about 16% of the world's human population.", "A sovereign transcontinental country comprising the mainland of the Australian continent, the island of Tasmania, and numerous smaller islands. With an area of 7,617,930 square kilometres, Australia is the largest country by area in Oceania and the world's sixth-largest country. Australia is the oldest, flattest, and driest inhabited continent, with the least fertile soils.", "A geographic region that includes Australasia, Melanesia, Micronesia and Polynesia. Spanning the Eastern and Western Hemispheres, Oceania has a land area of 8,525,989 square kilometres and a population of over 41 million. When compared with the continents, the region of Oceania is the smallest in land area and the second smallest in population after Antarctica." ) ) // Example to demonstrate automatic word wrap letsPlot() + geomMap(data = dataWithDescr, map = world, mapJoin = "region" to "continent", color = "white", tooltips = layerTooltips().title("@region").line("@|@description")) { fill = "region" } + theme(axis="blank", panelGrid="blank").legendPositionNone() + coordMap(ylim = -70 to 85) + ggsize(800,500)