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

**URL:** <https://discourse.julialang.org/t/how-to-plot-a-scatter-plot-where-the-each-specifies-of-the-iris-data-set-is-given-a-different-colour/25600>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [June 24, 2019, 12:05pm UTC](https://discourse.julialang.org/t/how-to-plot-a-scatter-plot-where-the-each-specifies-of-the-iris-data-set-is-given-a-different-colour/25600 "2019-06-24T12:05:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [June 24, 2019, 12:05pm UTC](https://discourse.julialang.org/t/how-to-plot-a-scatter-plot-where-the-each-specifies-of-the-iris-data-set-is-given-a-different-colour/25600/1 "2019-06-24T12:05:47Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)\
**Post date:** [June 24, 2019, 12:13pm UTC](https://discourse.julialang.org/t/how-to-plot-a-scatter-plot-where-the-each-specifies-of-the-iris-data-set-is-given-a-different-colour/25600/2 "2019-06-24T12:13:20Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 24, 2019, 12:16pm UTC](https://discourse.julialang.org/t/how-to-plot-a-scatter-plot-where-the-each-specifies-of-the-iris-data-set-is-given-a-different-colour/25600/3 "2019-06-24T12:16:32Z")

</div>

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
julia> using Plots

julia> p = plot()

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

julia> display(p)

```

 ![scatter_colours](https://global.discourse-cdn.com/julialang/original/3X/2/1/21475ba09ffea132d9a6f0ca002cc73cfc26cad0.png)

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

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

```
