0

I'm trying to plot different data files using Gadfly. I tried using a DataFrame, but with no result.

I tried using the below code but it just plots the last data file. I don´t know how to plot all the data file in just one plot using Gadfly.

data1 = CSV.read("DOC.CSV")
data2 = CSV.read("DODC.CSV")
data3 = CSV.read("DOTC.CSV")
data4 = CSV.read("DTC.CSV")
data5 = CSV.read("DTDC.CSV")
data6 = CSV.read("DTTC.CSV")
data = [data1,data2,data3,data4,data5,data6]

ddframe = DataFrame()

for i in 1:6
    ddframe[Symbol("Data"*string(i))]=DataFrame(x=data[i][!,1],y=data[i][!,2],label="Data "*string(i))
end

p = plot(ddframe,x="x",y="y",color="label",Geom.point,Geom.line,Guide.xlabel("Wavelength(nm)"),Guide.ylabel("Absorbance(UA)"),Guide.title("Absorbance Spectrum for
        Cianine dyes"))
  • this code is nor replicable (we do not have your data files) and hence we do not know what you need. Please provide a Minimal Working Example (MWE) where you are using data generated with the `rand()` function. – Przemyslaw Szufel Sep 06 '19 at 21:17

1 Answers1

1

I assume your data is like this.

│ x     │ y     │
│───────┼───────┤
│ 1     │ 1     │
│ 2     │ 3     │
│ 3     │ 5     │
│ 4     │ 7     │
│ 5     │ 9     │

Therefore, the data is an array of dataframes.

More, I assume a dataframe can be represented as a line (wavelength vs absorbance).
According to your code, you may combine every dataframe into a plot, so what you need is the layer() function.

plot(
     layer(data[1],
           x=:x,
           y=:y,
           Geom.point,
           Geom.line,
           Theme(default_color="red")),

     layer(data[2],
           x=:x,
           y=:y,
           Geom.point,
           Geom.line,
           Theme(default_color="blue"))
)
Pei Huang
  • 344
  • 1
  • 6