ObjectProfile / Roassal3

The Roassal Visualization Engine
MIT License
97 stars 52 forks source link

[Roassal3-Matplotlib] Class Names #104

Closed olekscode closed 4 years ago

olekscode commented 5 years ago

Needless to say that PLT is not a very good class name. I can propose to rename it to RSPlot. As for PLTPlot and PLTScatter, I would call them RSLinePlot and RSScatterPlot or RSLine and RSScatter (if possible).

Because it is a bit confusing to create a plot and add a plot to it.

plot := PLT new.
p := PLTPlot new.
plot addPlot: p.

But consider this: you create a plot and add a line to it:

plot := RSPlot new.
line := RSLine new.
plot add: line.

Or draw line on a plot:

plot draw: line.

This could be a nice API for drawing multiple things on one plot:

RSPlot new
    add: (RSScatterPlot new x: age y: salary)
    add: (RSLinePlot new x: age y: age * slope + intercept).

It is still a bit confusing to add ScatterPlot and LinePlot to Plot, so maybe we can take some inspiration from The Grammar of Graphics that was implemented as ggplot

ggplot-grammar-of-graphics-stack-1

Here are some examples of how we do things with ggplot:

library(ggplot2)

Scatterplot of sepal and petal length of iris flowers with 3 colors denoting classes (species) of flowers: setosa, versicolor, and virginica (the one that I built with Roassal3 and posted on Discord):

ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length)) +
  geom_point(aes(color = Species))

Scatter

Or the same thing with a regression line and a light theme:

ggplot(data = iris, aes(x = Sepal.Length, y = Petal.Length)) +
  geom_point(aes(color = Species)) + 
  geom_smooth(method='lm', formula= y~x) +
  theme_light()

ScatterRegression

I strongly do not recommend making a dependency on DataFrame, but we can take inspiration for the names. For example, RSLineGeometry and RSPointGeometry (or RSScatterGeometry):

sepalWidth := (iris column: 'sepal width').
petalWidth := (iris column: 'petal width').

points := RSPointGeometry new
    x: sepalWidth
    y: petalWidth.

regressionLine := RSLineGeometry new
    x: sepalWidth
    y: slope * sepalWidth + intercept.

RSPlot new
    add: points
    add: regressionLine.

I'm not sure if this is a good API, but I think that we can learn a lot from The Grammar of Graphics, and it seems like the right thing for Pharo

akevalion commented 4 years ago

At this moment the prefeix for all roassal classes is RS