%useLatestDescriptors %use lets-plot fun genWord(length:Int):String { val letters = ('a'..'z') return List(length) { letters.random() }.joinToString("") } fun genWordSet(n:Int):Set { val words = HashSet() while(words.size < n) { words.add(genWord(5)) } return words } fun data(n:Int, words:Set):Map { return mapOf( "word" to List(n) { words.random() }, "g" to List(n) { listOf('a','b','c').random() } ) } // Number of unique words exceeds threshold (50) of default 'pick' sampling on bar chart. val words = genWordSet(500) val dat = data(1000, words) val p = ggplot(dat) { x = "word" } // Disable sampling to see the overplotting. p + geomBar(sampling = samplingNone) // Draw plot with default sampling. p + geomBar() // 'pick' sampling preserves groups on bar chart. p + geomBar { fill="g" }