%useLatestDescriptors %use lets-plot @file:DependsOn("com.github.doyaaaaaken:kotlin-csv-jvm:0.7.3") import com.github.doyaaaaaken.kotlincsv.client.* val csvData = java.io.File("mpg.csv") val mpg: List> = CsvReader().readAllWithHeader(csvData) fun col(name: String, discrete: Boolean=false): List<*> { return mpg.map { val v = it[name] if(discrete) v else v?.toDouble() } } val df = mapOf( "displ" to col("displ"), "hwy" to col("hwy"), "cyl" to col("cyl"), "index" to col(""), "cty" to col("cty"), "drv" to col("drv", true), "year" to col("year") ) // Mapping letsPlot(df) {x = "displ"; y = "hwy"; color = "cyl"} + geomPoint(df) val p = letsPlot(df) p + geomPoint(df, stat = Stat.count()) {x = "displ"; color = "..count.."; size = "..count.."} val p = letsPlot(df) {x = "displ"; y = "hwy"; color = "cyl"} p + geomPoint(df, position = positionNudge()) + scaleColorContinuous("red", "green", guide = guideLegend(ncol=2)) + ggtitle("Displacement by horsepower") val p = letsPlot(df) {x = "displ"; y = "hwy"; color = "cyl"} p + geomPoint( data=df, position = positionNudge(), sampling = samplingRandomStratified(40) ) + scaleColorContinuous( "blue", "pink", guide = guideLegend(ncol=2) )