# Plot text at location

**URL:** <https://discourse.julialang.org/t/plot-text-at-location/63212>\
**Category:** General Usage\
**Tags:** makie, algebraofgraphics\
**Created:** [June 20, 2021, 1:49am UTC](https://discourse.julialang.org/t/plot-text-at-location/63212 "2021-06-20T01:49:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [June 20, 2021, 1:49am UTC](https://discourse.julialang.org/t/plot-text-at-location/63212/1 "2021-06-20T01:49:20Z")

</div>

@piever How can I set the location of text in AoG?

```julia
using AlgebraOfGraphics
using CairoMakie
using DataFrames

n = 500
df = DataFrame(x=1:n, y= collect(1:2:2n) .+ 10randn(n))
df = transform(df, :y => ByRow(x-> x%10==0 ? string(x) : "") => :txt)

data(df) * mapping(:x, :txt, position=:y) * visual(CairoMakie.Text) |> draw

```

MethodError: no method matching layout\_text

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [June 22, 2021, 5:47pm UTC](https://discourse.julialang.org/t/plot-text-at-location/63212/2 "2021-06-22T17:47:08Z")

</div>

There isn’t really a good way to do that at the moment, but it is a planned feature, see [Remaining gallery items · Issue #159 · JuliaPlots/AlgebraOfGraphics.jl (github.com)](https://github.com/JuliaPlots/AlgebraOfGraphics.jl/issues/159)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 22, 2021, 6:51pm UTC](https://discourse.julialang.org/t/plot-text-at-location/63212/3 "2021-06-22T18:51:20Z")

</div>

This ties a bit into the larger problem, what to do when plotting function positional arguments don’t conform to x,y,z. Text is one of the only plotting functions where the data positions are given in an attribute, not positional args. Maybe we should change that recipe if this turns out to be a major problem for downstream packages like AoG.

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [June 22, 2021, 6:55pm UTC](https://discourse.julialang.org/t/plot-text-at-location/63212/4 "2021-06-22T18:55:50Z")

</div>

I usually think of [geom\_text](https://ggplot2.tidyverse.org/reference/geom_text.html) and geom\_label as a scatterplot with a different marker shape, so making text conform to the scatter specification would make sense to me.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 22, 2021, 7:22pm UTC](https://discourse.julialang.org/t/plot-text-at-location/63212/5 "2021-06-22T19:22:49Z")

</div>

Yes that could be a good option, I thought the same

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [June 22, 2021, 8:28pm UTC](https://discourse.julialang.org/t/plot-text-at-location/63212/6 "2021-06-22T20:28:18Z")

</div>

Yes, the two main issues are

1. unusual argument order and
2. the categorical conversion pipeline gets in the way

To clarify problem 2. a bit, AoG always converts columns to numeric values before plotting. There are rare cases where plotting recipes accept lists of non numeric fields. One is plotting geometries (which are special cased in AoG) and the other is labels in a `Text` or `Annotations` plot, which would also need to be special cased.

If we changed the signature to `annotations(x, y, labels)`, or even better `annotations(x, y, label=labels)`, it should be easy enough to special case it and avoid the categorical conversion.

OTOH, `scatter(x, y, marker=labels)` would be a bit problematic from the AoG perspective, because it would be ambiguous with plotting a categorical variable with different markers. I think it’s better if it is clear from the keyword name that it should receive arbitrary strings.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 22, 2021, 8:57pm UTC](https://discourse.julialang.org/t/plot-text-at-location/63212/7 "2021-06-22T20:57:54Z")

</div>

I think the idea was not to use scatter, just the same argument order with x, y and marker for scatter is similar to string for text

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [June 22, 2021, 9:13pm UTC](https://discourse.julialang.org/t/plot-text-at-location/63212/8 "2021-06-22T21:13:05Z")

</div>

This would be an opportunity to introduce a `markermap` analogous to `colormap`. That way, `annotations(x,y, labels=labels)` could be implemented as `scatter(x, y, markers=labels, markermap=unique(labels))`. That is, it’s just a categorical variable, and the marker chosen for each value is determined by the markermap to be equal to the text of each label. Then no special casing is necessary.
