How to plot a scatter plot where the each specifies of the iris data set is given a different colour?

This seem quite easy with R’s ggplot2 but I can’t seem to figure it out with Plots.jl

I want to do a scatter plot of two numeric columns of the iris dataset and have the Species be the colour of each point. Of courses, Species isn’t a colour column, but the point is to have it choose a different colour for each specifies separately.

How do I do that using Plots.jl? Using Gadfly.jl it’s

using RDatasets
iris = dataset("datasets", "iris")
@df Gadfly.plot(x = iris[:PetalWidth], y = iris[:PetalLength], coour = iris[:Specifies])

but with Plots.jl I seem to need to specifies a mapping of Species to colours such as :red manually.

using StatsPlots
using RDatasets
iris = dataset("datasets", "iris")
@df iris scatter(:PetalWidth, :PetalLength, group = :Species)
1 Like

I feel like there’s something in StatsPlots that does this but can’t find it now. I guess you could always just loop through the different subsets of the data set and plot on the same graph, which would then assign a different colour to each new series?

julia> using Plots

julia> p = plot()

julia> for c in eachcol(rand(100, 4))
           scatter!(p, c)
       end

julia> display(p)

You would of course want to amend the loop to go through the different names in your data column, something like (untested):

for t in unique(iris.Specifies)
    scatter(p, iris[iris.Specifies .== t, PetalWidth], iris[iris.Specifies .== t, PetalLength], label = t)
end