Export to File
// Create random density data
val rand = java.util.Random(42)
val n = 500
val dataset = dataFrameOf(
"rating" to List(n / 2) { rand.nextGaussian() } + List(n / 2) { rand.nextGaussian() * 1.5 + 1.5 },
"cond" to List(n / 2) { "A" } + List(n / 2) { "B" }
)
// Density plot
val myPlot = plot(dataset) {
groupBy(cond) {
densityPlot(rating, trim = true) {
fillColor = Color.GREY
alpha = 0.6
borderLine.color("cond")
}
}
}
myPlot
Export PNG to file
val pathPNG = myPlot.save("myDensity.png")
javax.imageio.ImageIO.read(File(pathPNG))
Export SVG to file
val pathSVG = myPlot.save("myDensity.svg")
HTML(File(pathSVG).readText())
Export HTML to file
val pathHTML = myPlot.save("myDensity.html")
HTML(File(pathHTML).readText())
Last modified: 07 December 2023