I am loading multiple CSV files and want to plot them on top of each other, but I can’t figure out an easy way to change the line color and style to identify them in a legend.
Use vcat to make a single dataframe out of all, for dataframes it supports a src keyword I think with which you can create a new column in the process which holds the index that each row comes from. This column you can use as the color variable in AoG.
I think you are referring to the source kwarg in CSV.File/CSV.read:
• source: [only applicable for vector of inputs to CSV.File] a Symbol, String, or Pair of Symbol or String to Vector. As a single Symbol or String, provides the column name that will be added to the
parsed columns, the values of the column will be the input "name" (usually file name) of the input from whence the value was parsed. As a Pair, the 2nd part of the pair should be a Vector of values
matching the length of the # of inputs, where each value will be used instead of the input name for that inputs values in the auto-added column.
Ah right, my recommendation was based on the title - if the data is in CSVs it can be read into a single DataFrame with a source column with CSV, but if the separate DataFrames are desired for other purposes then indeed it might make sense to just vcat them for this.
Thanks. I actually made use of both suggestions to get my code quite compact.
The source argument to CSV.read creates one grouping and the source argument to vcat creates the other grouping.
using DataFrames, CSV, CairoMakie, AlgebraOfGraphics
# File Names
original_files = [
"1432H R models 2018/FirstThreadAxialStress.xls",
"1432H R models 2018/OldRepairAxialStress.xls",
"1432H R models 2018/NewRepairAxialStress.xls",
]
new_files = [
"1432H R models 2023/FirstThreadAxialStress.xls",
"1432H R models 2023/OldRepairAxialStress.xls",
"1432H R models 2023/NewRepairAxialStress.xls",
]
# Load and Categorize Data
df = vcat(
CSV.read.(
[original_files, new_files],
DataFrame,
source = "Path Location" => [
"First Thread",
"Old Repair Diameter",
"New Repair Diameter",
]
)...,
source = "Model" => ["Original Repair", "New Repair"]
)
# Plot Data
fig = draw(
data(df)
* mapping(
"S (in)" => "Distance from Inner Wall (in)",
"Normal Stress (psi)" => (x -> x./1000) => "Axial Stress (ksi)",
linestyle="Model",
color="Path Location",
)
* visual(Lines),
axis=(; title="Post-Repair Stresses"),
)
save("Post-Repair Stresses.png", fig)
display(fig)
Yeah it’s just a workaround after all. I wonder if it’s a good behavior to reset the axes like this but I assume it comes from the change when we didn’t run autolimits for every new plot anymore.