%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.
var mpg = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv")
mpg.head()
DataFrame: rowsCount = 5, columnsCount = 12
untitled | manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | audi | a4 | 1.800000 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
2 | audi | a4 | 1.800000 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
3 | audi | a4 | 2.000000 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
4 | audi | a4 | 2.000000 | 2008 | 4 | auto(av) | f | 21 | 30 | p | compact |
5 | audi | a4 | 2.800000 | 1999 | 6 | auto(l5) | f | 16 | 26 | p | compact |
val mpg32 = mpg.shuffle().take(32)
letsPlot(mpg32.toMap()) + geomDotplot {x = "hwy"}
geomDotplot()
and geomDensity()
¶val PACIFIC_BLUE = "#118ed8"
letsPlot(mpg32.toMap()) {x = "hwy"} +
geomDensity(fill = PACIFIC_BLUE) +
geomDotplot(binWidth = 1.5, fill = "white", color = PACIFIC_BLUE)
geomDotplot()
and geomHistogram()
¶letsPlot(mpg32.toMap()) {x = "hwy"} +
geomHistogram(binWidth = 1.5, color = "white") +
geomDotplot(method = "histodot", binWidth = 1.5, fill = "white", color = PACIFIC_BLUE)
stackDir
¶val plotBase = letsPlot(mpg32.toMap()) {x = "hwy"}
val plots = listOf(
plotBase + geomDotplot(binWidth = 1.5, stackDir = "up") + ggtitle("stackDir = \"up\""),
plotBase + geomDotplot(binWidth = 1.5, stackDir = "down") + ggtitle("stackDir = \"down\""),
plotBase + geomDotplot(binWidth = 1.5, stackDir = "center") + ggtitle("stackDir = \"center\""),
plotBase + geomDotplot(binWidth = 1.5, stackDir = "centerwhole") + ggtitle("stackDir = \"centerwhole\""),
)
gggrid(plots, 2, 400, 310, fit = true)
stackRatio
¶val plots1 = listOf(
plotBase + geomDotplot(binWidth = 1.5, stackRatio = 1) + ggtitle("stackRatio = 1"),
plotBase + geomDotplot(binWidth = 1.5, stackRatio = 0.5) + ggtitle("stackRatio = 0.5"),
plotBase + geomDotplot(binWidth = 1.5, stackRatio = 1.5) + ggtitle("stackRatio = 1.5"),
)
gggrid(plots1, 2, 400, 310, fit = true)
dotSize
¶val plots2 = listOf(
plotBase + geomDotplot(binWidth = 1.5, dotSize = 1) + ggtitle("dotSize = 1"),
plotBase + geomDotplot(binWidth = 1.5, dotSize = 0.5) + ggtitle("dotSize = 0.5"),
plotBase + geomDotplot(binWidth = 1.5, dotSize = 1.5) + ggtitle("dotSize = 1.5"),
)
gggrid(plots2, 2, 400, 310, fit = true)
center
¶val plots3 = listOf(
plotBase + geomDotplot(binWidth = 1.5, method = "histodot") + ggtitle("Default"),
plotBase + geomDotplot(binWidth = 1.5, method = "histodot", center = 11) + ggtitle("center = 11"),
)
gggrid(plots3, 2, 400, 310, fit = true)
boundary
¶val plots4 = listOf(
plotBase + geomDotplot(binWidth = 1.5, method = "histodot") + ggtitle("Default"),
plotBase + geomDotplot(binWidth = 1.5, method = "histodot", boundary = 12) + ggtitle("boundary = 12"),
)
gggrid(plots4, 2, 400, 310, fit = true)
bins
¶val plots5 = listOf(
plotBase + geomDotplot(method = "histodot") + ggtitle("Default (30)"),
plotBase + geomDotplot(method = "histodot", bins = 15) + ggtitle("bins = 15"),
)
gggrid(plots5, 2, 400, 310, fit = true)
plotBase +
geomDotplot(binWidth = 2, color="black") {fill = asDiscrete("cyl")} +
ggtitle("method='dotdensity'")
val plots6 = listOf(
plotBase + geomDotplot(method = "histodot", binWidth = 2, color = "black") {
fill = asDiscrete("cyl")
} + ggtitle("method='histodot'"),
plotBase + geomDotplot(method = "histodot", stackGroups = true, binWidth = 2, color = "black") {
fill = asDiscrete("cyl")
} + ggtitle("method='histodot', stackGroups = true"),
)
gggrid(plots6, 2, 400, 310, fit = true)
letsPlot(mpg32.toMap()) {x = "hwy"} +
geomDotplot(tooltips = layerTooltips()
.line("stack center|^x")
.line("Number of dots in stack|@..count..")
.line("Dot diameter|@..binwidth.."),
bins = 15)
val plotBase2 = plotBase +
scaleColorBrewer(type="qual", palette="Set1") +
scaleFillBrewer(type="qual", palette="Set1") +
themeGrey()
plotBase2 + geomDotplot(binWidth = 2) {
color = asDiscrete("cyl")
fill = asDiscrete("cyl")
} + facetGrid(x = "cyl") + ggtitle("facetGrid")
coordFlip()
¶letsPlot(mpg32.toMap()) {x = "hwy"} +
geomDotplot() + coordFlip()