# When using seriestype=:scatter, create individual labels for each dot?

**URL:** <https://discourse.julialang.org/t/when-using-seriestype-scatter-create-individual-labels-for-each-dot/104233>\
**Category:** Visualization\
**Tags:** recipe, plot\
**Created:** [September 25, 2023, 4:04pm UTC](https://discourse.julialang.org/t/when-using-seriestype-scatter-create-individual-labels-for-each-dot/104233 "2023-09-25T16:04:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [September 25, 2023, 4:04pm UTC](https://discourse.julialang.org/t/when-using-seriestype-scatter-create-individual-labels-for-each-dot/104233/1 "2023-09-25T16:04:38Z")

</div>

I am using Plot recipes to create a plot overload for a special type of input.

The result is a scatter plot with something like:

```julia
@recipe function f(ms::MyStruct)
    seriestype --> :scatter
    ms.x_vals, ms.y_vals
end

```

How do I create individual labels for each of the dots? If I do e.g.

```julia
label --> "Dot " .* string.(1:length(ms.x_vals))

```

I get a single label like `["Dot 1", "Dot 2", ...]`. Is there a way around it? I could do it with several plot commands (`plot` followed by `plot!`), but I am not sure how to combine this with plot recipes.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 25, 2023, 6:26pm UTC](https://discourse.julialang.org/t/when-using-seriestype-scatter-create-individual-labels-for-each-dot/104233/2 "2023-09-25T18:26:04Z")

</div>

`series_annotations`

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [September 25, 2023, 8:46pm UTC](https://discourse.julialang.org/t/when-using-seriestype-scatter-create-individual-labels-for-each-dot/104233/3 "2023-09-25T20:46:16Z")

</div>

That put the labels on the dots themselves, but I just want an ordinary label, e.g.:

```julia
plot(1:4, 2:2:8, seriestype=:scatter; series_annotations=["A", "B", "C", "D"], label=["A", "B", "C", "D"], color=1:4)

```

gives  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/6/f613642e4f33108038345a08280008a41c5e82ee.png)  
but I want something like  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/a/1ae617cb452255e78da8b15905e59c47f6df765e.png)

---

<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:** [September 26, 2023, 4:44am UTC](https://discourse.julialang.org/t/when-using-seriestype-scatter-create-individual-labels-for-each-dot/104233/4 "2023-09-26T04:44:41Z")

</div>

Transpose the vector of labels.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 26, 2023, 5:56am UTC](https://discourse.julialang.org/t/when-using-seriestype-scatter-create-individual-labels-for-each-dot/104233/5 "2023-09-26T05:56:59Z")

</div>

You need each point to be it’s own series to do that, that’s the internal logic. To create new series in a recipe, use the `@series` macro:

```julia
@recipe function f(ms::MyStruct)
     seriestype --> :scatter
     for i in eachindex(ms.x_vals)
         @series begin
             label := "Dot $i"
             ms.x_vals[i:i], ms.y_vals[i:i]
         end
     end
end

```

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [September 26, 2023, 3:50pm UTC](https://discourse.julialang.org/t/when-using-seriestype-scatter-create-individual-labels-for-each-dot/104233/6 "2023-09-26T15:50:29Z")

</div>

> [@mkborregaard](#):
>
> ```julia
> @recipe function f(ms::MyStruct)
> seriestype --> :scatter
> for i in eachindex(ms.x_vals)
> @series begin
> label := "Dot $i"
> ms.x_vals[i:i], ms.y_vals[i:i]
> end
> end
> end
> 
> ```

Thanks a lot, that works 🙂
