# Gadfly Geom.line not in order

**URL:** <https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019>\
**Category:** Visualization\
**Created:** [June 8, 2020, 10:15pm UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019 "2020-06-08T22:15:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Anderson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris_anderson/32/9465_2.png) [@Chris\_Anderson](https://discourse.julialang.org/u/Chris_Anderson)\
**Post date:** [June 8, 2020, 10:15pm UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019/1 "2020-06-08T22:15:47Z")

</div>

I produced a table that I then plotted. The plot is all wonky though, the values have mixed themselves up to make a perfect line. See below.

`graph = plot(a, x = :Years_mean, y = :Overall_mean, Geom.line)`  
 ![line](https://global.discourse-cdn.com/julialang/original/3X/1/a/1a99f9478f08718dc97cdbffb672e57771c0b28a.png)

How do I get it back to normal? Or what did I do to screw it up?

Thanks

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [June 8, 2020, 11:42pm UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019/2 "2020-06-08T23:42:00Z")

</div>

Can you provide a minimal example of what `a` is? Gadfly distinguishes between continuous and discrete variables, and so there may be multiple options to do what you want, depending on whether the original data is continuous, discrete, or a TimeType.

---

<div class="post-metadata">

**Author:** ![Chris\_Anderson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris_anderson/32/9465_2.png) [@Chris\_Anderson](https://discourse.julialang.org/u/Chris_Anderson)\
**Post date:** [June 8, 2020, 11:57pm UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019/3 "2020-06-08T23:57:58Z")

</div>

Here is a sample. Both columns are type `any`. Row two is blank. All values were rounded to `digits = 2`. I had a little trouble putting the df here, had to delete some info, so I hope I didn’t lose anything valuable.

```julia
│ Overall_mean │ Years_mean │
│ 80.37 │ 9.3 │
│ │ │
│ 95.23 │ 9.03 │
│ 90.7 │ 4.57 │
│ 89.57 │ 9.75 │
│ 88.36 │ 16.43 │
│ 88.02 │ 3.75 │
│ 85.47 │ 10.22 │
│ 85.31 │ 7.9 │
│ 83.7 │ 5.1 │
│ 82.92 │ 7.1 │
│ 80.55 │ 11.79 │
│ 80.43 │ 9.0 │
│ 79.53 │ 4.53 │
│ 79.17 │ 6.62 │
│ 78.71 │ 10.4 │
│ 78.22 │ 9.22 │

```

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [June 8, 2020, 11:59pm UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019/4 "2020-06-08T23:59:54Z")

</div>

What are the blank values e.g. " " or “”?

---

<div class="post-metadata">

**Author:** ![Chris\_Anderson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris_anderson/32/9465_2.png) [@Chris\_Anderson](https://discourse.julialang.org/u/Chris_Anderson)\
**Post date:** [June 9, 2020, 12:05am UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019/5 "2020-06-09T00:05:03Z")

</div>

They are " ". What’s that other one you typed?

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [June 9, 2020, 12:25am UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019/6 "2020-06-09T00:25:24Z")

</div>

Your data is messy because your mixing different types which don’t promote well. Even something like this won’t work:

```julia
replace(a, " "=>NaN)

```

My solution is:

```julia
a0 = [ 80.37 9.3; " " " "; 95.23 9.03; 90.7 4.57; 89.57 9.75;     
 88.36 16.43; 88.02 3.75; 85.47 10.22 ; 85.31 7.9;       
 83.7 5.1; 82.92 7.1; 80.55 11.79 ; 80.43 9.0 ;     
 79.53 4.53; 79.17 6.62; 78.71 10.4; 78.22 9.22]       
a = DataFrame(a0, [:Years_mean, :Overall_mean])
 [x[isa.(x, String)] .= NaN for x in eachcol(a)]

# or
ifelse.(isa.(a, String), NaN, a)

a

```

The [DataFrames docs](http://juliadata.github.io/DataFrames.jl/stable/) might provide further help.

---

<div class="post-metadata">

**Author:** ![Chris\_Anderson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris_anderson/32/9465_2.png) [@Chris\_Anderson](https://discourse.julialang.org/u/Chris_Anderson)\
**Post date:** [June 9, 2020, 12:50am UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019/7 "2020-06-09T00:50:11Z")

</div>

Thank you. I’ll give that a try. So basically if those blanks weren’t there it ought to work because then everything would be the same type?

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [June 9, 2020, 12:57am UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019/8 "2020-06-09T00:57:04Z")

</div>

Yes, it should work if columns are of the same type. In Gadfly, you can try to make variables discrete or continuous by adding `e.g. Scale.x_discrete` or `Scale.x_continuous`, but that will only work if the values can be promoted to a discrete or continuous type.

---

<div class="post-metadata">

**Author:** ![Humphrey\_Lee](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@Humphrey\_Lee](https://discourse.julialang.org/u/Humphrey_Lee)\
**Post date:** [June 9, 2020, 5:43am UTC](https://discourse.julialang.org/t/gadfly-geom-line-not-in-order/41019/9 "2020-06-09T05:43:31Z")

</div>

In my work, I opted to drop missing values

```julia
df = dropmissing(df, :Overall_mean)

```

for DataFrames.
