# Plot a range of dataframe columns

**URL:** <https://discourse.julialang.org/t/plot-a-range-of-dataframe-columns/7391>\
**Category:** New to Julia\
**Tags:** question, plotting\
**Created:** [November 29, 2017, 7:09pm UTC](https://discourse.julialang.org/t/plot-a-range-of-dataframe-columns/7391 "2017-11-29T19:09:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)\
**Post date:** [November 29, 2017, 7:09pm UTC](https://discourse.julialang.org/t/plot-a-range-of-dataframe-columns/7391/1 "2017-11-29T19:09:27Z")

</div>

Is there way to plot a range of columns using Plots and Dataframes?

I’ve managed to successfully load my text file of data and plot a selection of it (this is using Plots and the new Dataframs 0.11). But is there a way to indicate a large number of dataframe columns?

For example if I have

```julia
    using DataFrames, Plots, StatPlots, CSV

    spectra=CSV.read(Filename)

    @df spectra plot(:Freq, [:Mic28 :Mic29 :Mic30])

```

is there a way to instead select Mic28-Mic30 or the equivalent columns 32-34? (In reality I’m trying to plot more than these three, I have 48 columns to plot at once).

---

<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:** [November 29, 2017, 10:42pm UTC](https://discourse.julialang.org/t/plot-a-range-of-dataframe-columns/7391/2 "2017-11-29T22:42:34Z")

</div>

Have you tried:

```julia
 @df spectra plot(:Freq, cols(32:34))

```

There is an example of using `cols` [here](https://github.com/JuliaPlots/StatPlots.jl#corrplot-and-cornerplot). The legend doesn’t yet get automatically labelled with the column names but I plan on getting back to that as soon as I have a bit more time. To get the correct legend I think you need to do:

```julia
 @df spectra plot(:Freq, cols(32:34), label = names(spectra)[32:34])

```

---

<div class="post-metadata">

**Author:** ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)\
**Post date:** [November 30, 2017, 1:03pm UTC](https://discourse.julialang.org/t/plot-a-range-of-dataframe-columns/7391/3 "2017-11-30T13:03:39Z")

</div>

Thank you! That did precisely what I needed. I had checked the docs for both dataframes and plots but neglected to check those of StatPlots.
