HE Prog HE Prog - 12 days ago 5
R Question

How to have a scatter plot with mutiple axes in R

In R, the iris table contains the following attributes:


  • Sepal.Length

  • Sepal.Width

  • Petal.Length

  • Petal.Width

  • Species



I have learned that it's possible to use the following package to view a scatter plot of 2 values only in the dataset which are Sepal.Length & Sepal.Width in this case:

library(ggvis)
iris %>% ggvis(~Sepal.Length, ~Sepal.Width, fill = ~Species) %>%
layer_points()


My question is as follows:
I need to have the scatter plot but for the the first 4 attributes in the dataset to represent the species. How can this be done?

If not in R, is there any other tool that can do this?

Answer

You can use the built-in functin pairs. If you want to add colors to it as in your example, you can add parameter col. Here you have the code:

pairs(iris[,1:4], col = iris$Species, pch=16) # parameter pch=16 changes the points to be filled dots.

Output:

enter image description here