# Gadfly boxplot is getting plotted like a vertical straight line (missing the box part)

**URL:** <https://discourse.julialang.org/t/gadfly-boxplot-is-getting-plotted-like-a-vertical-straight-line-missing-the-box-part/80946>\
**Category:** Visualization\
**Tags:** gadfly\
**Created:** [May 12, 2022, 10:40am UTC](https://discourse.julialang.org/t/gadfly-boxplot-is-getting-plotted-like-a-vertical-straight-line-missing-the-box-part/80946 "2022-05-12T10:40:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkmalaiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rkmalaiya/32/31236_2.png) [@rkmalaiya](https://discourse.julialang.org/u/rkmalaiya)\
**Post date:** [May 12, 2022, 10:40am UTC](https://discourse.julialang.org/t/gadfly-boxplot-is-getting-plotted-like-a-vertical-straight-line-missing-the-box-part/80946/1 "2022-05-12T10:40:42Z")

</div>

Hello,

I am trying to make a boxplot using Gadfly but all I see are straight vertical lines. Also, this seems to be a very tricky issue. It only happens for a specific combination of data points, and I am not able to figure out what’s wrong. I have replicated the issue using fake data below, please help me understand what may I be missing?

Also, there are 2 issues that this dataset is causing.

1. The major issue is that I am seeing all vertical lines
2. If I try to make the plot differently, I do see box plots but then the left most and the right most end of the plot is getting trimmed away.

**Fake Data**

> df\_plot = vcat(  
> DataFrame(model = repeat([“one”,“two”, “three”],inner=242),  
> type = repeat([“type1”],outer=726),  
> data=rand(726)),
> 
> DataFrame(model = repeat([“four”, “five”, “six”],inner=242),  
> type = repeat([“type2”],outer=726),  
> data=rand(726)))  
> ![image](https://global.discourse-cdn.com/julialang/original/3X/7/e/7e0d5efaf904deee584d1ed5c9e223e6c5dd8608.png)

_Some more information about the data_  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/d/1d1574baa150e0334016b0d294cd5c68f9bc9895.png)

**Plot (issue 1)**

> Gadfly.plot(df\_plot,  
> x = :type,  
> y=:data,  
> color=:model,  
> Geom.boxplot  
> )
> 
> ![image](https://global.discourse-cdn.com/julialang/original/3X/0/5/0524eb8c394741caa0c3c606c7b623c324f0ccdd.png)

**Plot (issue 2)**  
Gadfly.plot(df\_plot,  
x=:model,  
y=:data,  
color = :type, # swapped color and x aesthetics  
Geom.boxplot,  
)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/d/0dbf8c51e0e936e406e06ab398e89cadf14da2ae.png)

I tried to increase the width of the plot using

> set\_default\_plot\_size(10inch, 4inch)

but the issue still remains

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/f/df724ce7ae5ba649a69159317bde1fe8539f55b6.png)

Thank you for all the help!

---

<div class="post-metadata">

**Author:** ![rkmalaiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rkmalaiya/32/31236_2.png) [@rkmalaiya](https://discourse.julialang.org/u/rkmalaiya)\
**Post date:** [June 17, 2022, 5:06pm UTC](https://discourse.julialang.org/t/gadfly-boxplot-is-getting-plotted-like-a-vertical-straight-line-missing-the-box-part/80946/2 "2022-06-17T17:06:41Z")

</div>

> [@rkmalaiya](#):
>
> Plot (issue 2)

I would really appreciate if anyone can help with a workaround for issue 2. It’s a bit important for me right now. By workaround I mean if I can make any adjustments through spacing etc in Themes to fix the issue. I cannot really change the format of the plot given the actual requirement in my work where this (kind of) plot is needed.

Thanks a lot for the help!

---

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [June 19, 2022, 6:41pm UTC](https://discourse.julialang.org/t/gadfly-boxplot-is-getting-plotted-like-a-vertical-straight-line-missing-the-box-part/80946/3 "2022-06-19T18:41:57Z")

</div>

gadfly is getting confused because the models for type1 (one, two, three) are not the same as the models for type 2 (four, five, six). is this really the nature of your data? if i change your example so that they are (ie type2 models are also one, two, three), then the output looks reasonable:

```julia
df_plot = vcat(
       DataFrame(model = repeat(["one","two", "three"],inner=242),
       type = repeat(["type1"],outer=726),
       data=rand(726)),

       DataFrame(model = repeat(["one", "two", "three"],inner=242),
       type = repeat(["type2"],outer=726),
       data=rand(726)))

```

```julia
plot(df_plot,
       x = :model,
       y=:data,
       color=:type,
       Geom.boxplot
       )

```

 ![Screen Shot 2022-06-19 at 2.39.59 PM](https://global.discourse-cdn.com/julialang/original/3X/7/9/7996394ce4c84d40bbb56e468eb2883dfe4b6a4b.png)

```julia
plot(df_plot,
       x = :type,
       y=:data,
       color=:model,
       Geom.boxplot
       )

```

 ![Screen Shot 2022-06-19 at 2.40.07 PM](https://global.discourse-cdn.com/julialang/original/3X/6/2/626745d82e18243f7803d9578a45626b7f8985a5.png)

---

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [June 19, 2022, 6:53pm UTC](https://discourse.julialang.org/t/gadfly-boxplot-is-getting-plotted-like-a-vertical-straight-line-missing-the-box-part/80946/4 "2022-06-19T18:53:41Z")

</div>

as a workaround, if that is truly the nature of your data, i would just make two plots using different slices of the dataframe:

```julia
julia> type1 = Gadfly.plot(df_plot[df_plot.type.=="type1", :],
       x = :model,
       y=:data,
       Geom.boxplot,
       Guide.title("type1"));

julia> type2 = Gadfly.plot(df_plot[df_plot.type.=="type2", :],
       x = :model,
       y=:data,
       Geom.boxplot,
       Guide.title("type2"));

julia> hstack(type1, type2)

```

 ![Screen Shot 2022-06-19 at 2.53.10 PM](https://global.discourse-cdn.com/julialang/original/3X/4/4/44b2a887dfdf51c98a7d942f29546acb537e72c8.png)

---

<div class="post-metadata">

**Author:** ![rkmalaiya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rkmalaiya/32/31236_2.png) [@rkmalaiya](https://discourse.julialang.org/u/rkmalaiya)\
**Post date:** [June 20, 2022, 6:26pm UTC](https://discourse.julialang.org/t/gadfly-boxplot-is-getting-plotted-like-a-vertical-straight-line-missing-the-box-part/80946/5 "2022-06-20T18:26:24Z")

</div>

Thanks a lot @bjarthur for the workaround suggestion.

Yes, that’s the nature of the data. I have two different categories that defines my models. I want the x axis to show a property of the model (which I represented as one, two, three here). Given both categories do not have any overlapping properties, my x-axis is unique between categories.

I wanted readers to clearly see the two categories (it’s not obvious from the x-axis). Hence, I was playing with either differentiating the categories by grids or by color. This way I was hoping, the different categories will pop out to the readers.

Also I am putting the property of the model in x axis because the y axis metric has a linear (kind of) relation with x axis (property of model). Interestingly, as the category changes, the degree of linear relationship changes too. Hence, I wanted to pop this information in my graph.

Thanks again!
