lets-plot-kotlin
lets-plot-kotlin copied to clipboard
Add possibility to create a pie chart, a bar chart with horizontal bars
It would be nice to have pie chart and bar chart with horizontal bars support
Yes, we are planning to have horizontal bars (and some other directional geometries).
As for pie char, this more difficult, but we are planning to have "waffle plot" which can work as a replacement for pie chart.
I would like to ask a couple of questions
- It would be interesting to know where you see the difficulty of adding a pie chart. I have some sort of workaround. I understand that if I save this to svg then the image size will be quite large. Can you please describe other disadvantages of my approach or maybe you can suggest your own

- The second question is a bit off-topic, but still I'm interested in how to do it. Suppose I want to make a chart like this. I managed to do something similar using facet. Is it possible to achieve this effect without using facets? Is it possible to somehow control the distance between bars?
Thanks in advance for your answers!
On the 2nd, try:
geomBar(stat..., position = Pos.dodge) { x = "category"; ...
In Lets-Plot everything boils down to points in some coordinate system. To implement idiomatic Pie Chart we would have to use polar coordinate system which is not yet supported. Adding support for polar coordinate system is difficult (but also very cool).
But you are right: noneidiomatic solution for pie chart can be done with lesser efforts. Your solution is original but a bit extreme. Could you try to build sectors using geomPolygon?
Yay, this is a cleaner way to do this. Thanks a lot for your answers and help!

Very cool ) Do you order slices? I've read somewhere that pie chart looks the best when the 1st biggest slice goes to the left from 12 o'clock and all other slices go clockwise in descending order:

Good concept). Now I put the slices in descending order except the last slice. The last slice is the sum of all the remaining values to ensure that only the largest X number of slices are displayed, and the rest are combined

In mathematics, it is possible to move from one coordinate system to another. Converting between polar and Cartesian coordinates looks like this
Let's say we have a semicircle. Here is an example of converting it to polar coordinates
It seems like a pie chart can be built using this conversion. And when the polar coordinate system is supported, it will be easy to switch to using it. Maybe it is possible to do such an implementation for now to avoid waiting for polar coordinates support. What do you think?)
Would be perfect if the biggest slice was to the left of 12 o'clock ) :

In mathematics...
Exactly, this is how polar coordinate system should project X, Y etc. aesthetics to the display space. X-axis becomes a circle, bars are translated to slices and all other geometries are distorted accordingly.
https://ggplot2.tidyverse.org/reference/coord_polar.html
@alshan Thanks a lot for adding coordFlip! A bar chart with horizontal bars is now possible 🎉
@KirylBubovich You are very welcome ) I remember about coordPolar but couldn't find a resource to work on it unfortunately.
No worries, thank you for being transparent. I appreciate your work and time)
geomPie added in v4.2.0
@alshan Thank you so much!