Points (XY Scatter plot)

We can study the relation between two numerical variables by drawing one point for each instance.

Example 1

Scope: Study which is the relation between petal-length and sepal-length from iris data set.

Solution:

WS.draw(points(iris.getVar("petal-length"), iris.getVar("petal-width")));
  • iris.var("petal-length") - variable used to define horizontal axis

  • iris.var("petal-width") - variable used to define vertical axis

Scatter XY points for `petal-length` and `petal-width` variables
Figure 1.7.2.1 Scatter XY points for `petal-length` and `petal-width` variables

Example 2

Scope: Study which is the relation between petal-length and sepal-length from iris data set. Color each point with a different color corresponding with value from variable class and add a legend for colors.

Solution:

WS.draw(points(iris.getVar("petal-length"), iris.getVar("petal-width"),
    color(iris.var("class")), pch(2))
        .legend(1.5, 2.2, labels("setosa", "versicolor", "virginica"));
Scatter XY points for `petal-length` and `petal-width` variables with colors and legend
Figure 1.7.2.2 Scatter XY points for `petal-length` and `petal-width` variables with colors and legend
  • iris.getVar("petal-length") - variable used to define horizontal axis

  • iris.getVar("petal-width") - variable used to define vertical axis

  • color(iris.getVar("class")) - nominal variable which provides indexes to select colors from current palette

  • pch(2) - select the type of figure used to draw points (in this case is a circle filled with solid color and a black border)

  • legend(1.5, 2.2, labels("setosa", "versicolor", "virginica")) - adds a legend at the specific position specified in the data range; labels are specified by parameter, colors are taken as default from current palette starting with 1

results matching ""

    No results matching ""