# How to make this graph more beautiful?

**URL:** https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912
**Category:** General Usage
**Tags:** plots, statsplots
**Created:** [June 17, 2022, 11:16am UTC](https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912 "2022-06-17T11:16:08Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)
#### Post date: [June 17, 2022, 11:16am UTC](https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912/1 "2022-06-17T11:16:08Z")

</div>

Dear all, I want to add annotations in scatter plot. But the annotations are very large, how to make it smaller and beautiful?

```julia
julia> using DataFrames, RDatasets, Plots

julia> df = dataset("datasets", "iris");

julia> scatter(df.SepalLength, df.SepalWidth, series_annotation = df.Species)

```

 ![截屏2022-06-17 19.13.33](https://global.discourse-cdn.com/julialang/original/3X/5/0/50ec0a47afb45b766a436610c4fd2c143e41bf70.jpeg)

---

<div class="post-metadata">

### Author: ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)
#### Post date: [June 17, 2022, 11:17am UTC](https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912/2 "2022-06-17T11:17:29Z")

</div>

I try to make the annotations smaller, but it does not work

```julia
julia> scatter(df.SepalLength, df.SepalWidth, series_annotation = df.Species, annotationfontsize = 5)

```

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [June 17, 2022, 12:26pm UTC](https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912/3 "2022-06-17T12:26:48Z")

</div>

Rather than annotating all 150 values, group your data by the specie and then print them in 3 different colours with the species in the legend…

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [June 17, 2022, 10:35pm UTC](https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912/4 "2022-06-17T22:35:13Z")

</div>

Fyi, StatsPlots is perfect for this:

```julia
using StatsPlots
@df df scatter(:SepalLength, :SepalWidth, group=:Species)

```

But to answer your original question, you can broadcast Plots’ function `text()` to set the `series_annotation` attributes:

```julia
scatter(df.SepalLength, df.SepalWidth, ms=2, series_annotation = text.(df.Species, :blue, :bottom, 5))

```

---

<div class="post-metadata">

### Author: ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)
#### Post date: [June 17, 2022, 11:09pm UTC](https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912/5 "2022-06-17T23:09:28Z")

</div>

@rafael.guerra Thanks so much. This is what I want. But I have another question. Here is an simply example.

```julia
julia> data = rand(10, 2);

julia> df = DataFrame(data, :auto);

julia> city = ["Shanghai", "Beijing", "Nanjing", "Tangshan", "Tianjin", "Wuhan", "Chongqing", "Heifei", "Hangzhou", "Ningbo"];

julia> insertcols!(df, 1, :city => city);

julia> scatter(df.x1, df.x2, series_annotation = text.(df.city, :magenta, :top, 7), leg = false)

```

 ![截屏2022-06-18 07.05.01](https://global.discourse-cdn.com/julialang/original/3X/9/b/9b5c361e0488d00f3bc3e9c3e804ddd4e59ddac3.png)

In the graph , I want to adjust “Nanjing” to the right, “Beijing” to the right. and make the text a little far from the marker.

---

<div class="post-metadata">

### Author: ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)
#### Post date: [June 17, 2022, 11:12pm UTC](https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912/6 "2022-06-17T23:12:24Z")

</div>

I major in Economics, we often need to add the annotations to the scatter plot.

---

<div class="post-metadata">

### Author: ![Raymond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raymond/32/36557_2.png) [@Raymond](https://discourse.julialang.org/u/Raymond)
#### Post date: [June 17, 2022, 11:20pm UTC](https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912/8 "2022-06-17T23:20:08Z")

</div>

Can you help me to modify the code?

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [June 18, 2022, 6:40am UTC](https://discourse.julialang.org/t/how-to-make-this-graph-more-beautiful/82912/9 "2022-06-18T06:40:55Z")

</div>

To change the label positions for a given plot manually you can use the following syntax by providing the annotations coordinates:

```julia
scatter(df.x1, df.x2; annotation = (x, y, text.(df.city, :magenta, 6)), leg=false)

```

Just change x, y around df.x1, df.x2, with the required offsets.

The general problem is very difficult. It would be easier to abbreviate the city names to 2 or 3 letters max and annotate randomly around the points. See [this other thread](https://discourse.julialang.org/t/how-to-make-this-plot-in-julia/75065/4).
