Skip to content

Commit

Permalink
Change indent to 4 (#3)
Browse files Browse the repository at this point in the history
* Change indent to 4

* Format code with JuliaFormatter
  • Loading branch information
jotas6 authored Apr 9, 2024
1 parent dd8bcfa commit 9bf90b0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
indent = 2
indent = 4
format_docstrings = true
46 changes: 23 additions & 23 deletions 02-mappings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,56 @@ include("01-layers.jl")

# Coloring
plt_colors =
data(demographics_df) * mapping(
:AGE,
:WEIGHT;
color = :ISMALE, # We want to have different colors according to sex
) * visual(Scatter)
data(demographics_df) * mapping(
:AGE,
:WEIGHT;
color = :ISMALE, # We want to have different colors according to sex
) * visual(Scatter)
draw(plt_colors) # Works, but it is interpreting :ISMALE as a continuous variable

## We can tell AoG that :ISMALE is categorical with nonnumeric
plt_colors =
data(demographics_df) *
mapping(:AGE, :WEIGHT; color = :ISMALE => nonnumeric) *
visual(Scatter)
data(demographics_df) *
mapping(:AGE, :WEIGHT; color = :ISMALE => nonnumeric) *
visual(Scatter)
draw(plt_colors) # Now it works as expected

# Markers
plt_markers =
data(demographics_df) *
mapping(:AGE, :WEIGHT; marker = :ISMALE => nonnumeric) *
visual(Scatter)
data(demographics_df) *
mapping(:AGE, :WEIGHT; marker = :ISMALE => nonnumeric) *
visual(Scatter)
draw(plt_markers)

## Tip: you can combine different arguments in a single plot
plt_combined =
data(demographics_df) *
mapping(:AGE, :WEIGHT; color = :ISMALE => nonnumeric, marker = :ISMALE => nonnumeric) *
visual(Scatter)
data(demographics_df) *
mapping(:AGE, :WEIGHT; color = :ISMALE => nonnumeric, marker = :ISMALE => nonnumeric) *
visual(Scatter)
draw(plt_combined)

## There are many more options depending on the type of plot that you are creating

# Faceting
## Columns
plt_cols =
data(demographics_df) *
mapping(:AGE, :WEIGHT; col = :ISMALE => nonnumeric) *
visual(Scatter)
data(demographics_df) *
mapping(:AGE, :WEIGHT; col = :ISMALE => nonnumeric) *
visual(Scatter)
draw(plt_cols)

## Rows
plt_rows =
data(demographics_df) *
mapping(:AGE, :WEIGHT; row = :ISMALE => nonnumeric) *
visual(Scatter)
data(demographics_df) *
mapping(:AGE, :WEIGHT; row = :ISMALE => nonnumeric) *
visual(Scatter)
draw(plt_rows)

## Layout
df_iv = dataset("iv_sd_1") # New dataset

plt_subjects =
data(df_iv) * # Concentration profiles for each subject
mapping(:time, :conc; layout = :id => nonnumeric) *
visual(Lines) # New type of plot (we will see more later)
data(df_iv) * # Concentration profiles for each subject
mapping(:time, :conc; layout = :id => nonnumeric) *
visual(Lines) # New type of plot (we will see more later)
draw(plt_subjects)
14 changes: 7 additions & 7 deletions 03-geometries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using DataFramesMeta # We will do some minimal data wrangling

# Mean age for each sex group
mean_ages = @by demographics_df :ISMALE begin
:AGE = mean(:AGE)
:AGE = mean(:AGE)
end

data(mean_ages) * mapping(:ISMALE => nonnumeric, :AGE) * visual(BarPlot) |> draw # We use the piping operator
Expand All @@ -21,8 +21,8 @@ data(demographics_df) * mapping(:AGE) * histogram() |> draw

# ScatterLines: Scatter + Lines
iv_summary = @by df_iv [:time, :dose] begin # Mean concentration profile for each dose level
:conc_mean = mean(:conc)
:conc_std = std(:conc)
:conc_mean = mean(:conc)
:conc_std = std(:conc)
end

data(iv_summary) *
Expand All @@ -34,10 +34,10 @@ visual(ScatterLines) |> draw
# Error bars
data(iv_summary) *
mapping(
:time,
:conc_mean,
:conc_std; # Error bar length
color = :dose => nonnumeric,
:time,
:conc_mean,
:conc_std; # Error bar length
color = :dose => nonnumeric,
) *
visual(Errorbars) |> draw # We only get the error bars

Expand Down
22 changes: 11 additions & 11 deletions 04-algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ include("03-geometries.jl")

# Mean concentration on top of all concentration profiles for each dose level
plt_mean =
data(iv_summary) *
mapping(:time, :conc_mean; layout = :dose => nonnumeric) *
visual(ScatterLines)
data(iv_summary) *
mapping(:time, :conc_mean; layout = :dose => nonnumeric) *
visual(ScatterLines)
draw(plt_mean) # So far we only have the mean concentration profiles

plt_all =
data(df_iv) *
mapping(
:time,
:conc;
layout = :dose => nonnumeric,
group = :id => nonnumeric, # Required
) *
visual(ScatterLines; color = (:grey, 0.5)) # We will talk more about customization later
data(df_iv) *
mapping(
:time,
:conc;
layout = :dose => nonnumeric,
group = :id => nonnumeric, # Required
) *
visual(ScatterLines; color = (:grey, 0.5)) # We will talk more about customization later
draw(plt_all) # Here we only have all the concentration profiles

# We can add both plots
Expand Down
68 changes: 34 additions & 34 deletions 05-customization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,49 @@ data(demographics_df) * mapping(:AGE, :WEIGHT) * visual(Scatter) |> draw # The a
# We can customize axis labels with =>
data(demographics_df) *
mapping(
:AGE => "Age (years)", # :column_name => "display name"
:WEIGHT => "Weight (kg)",
:AGE => "Age (years)", # :column_name => "display name"
:WEIGHT => "Weight (kg)",
) *
visual(Scatter) |> draw

## Tip: you can also use this syntax to apply transformations
data(demographics_df) *
mapping(
:AGE => round => "Age (years)", # :column_name => function => "display name"
:WEIGHT => (i -> i * 2.2) => "Weight (lb)",
:AGE => round => "Age (years)", # :column_name => function => "display name"
:WEIGHT => (i -> i * 2.2) => "Weight (lb)",
) *
visual(Scatter) |> draw

## Other customizations
### Scales
plt_iv =
data(iv_summary) *
mapping(
:time => "Time (hours)",
:conc_mean => "Concentration (μg/L)";
color = :dose => nonnumeric => "Dose (mg)", # Also applies to keyword arguments
) *
visual(ScatterLines)
data(iv_summary) *
mapping(
:time => "Time (hours)",
:conc_mean => "Concentration (μg/L)";
color = :dose => nonnumeric => "Dose (mg)", # Also applies to keyword arguments
) *
visual(ScatterLines)

draw(plt_iv) # Same plot as before

draw(plt_iv; axis = (; # NamedTuple
yscale = log10 # We now added a logarithmic scale
# Also works for xscale
yscale = log10 # We now added a logarithmic scale
# Also works for xscale
))

## Ticks
draw(plt_iv; axis = (; yscale = log10, yticks = [1, 10, 100], xticks = 0:2:24))

## Title
draw(
plt_iv;
axis = (;
yscale = log10,
yticks = [1, 10, 100],
xticks = 0:2:24,
title = "Mean concentration profile for each dose level",
),
plt_iv;
axis = (;
yscale = log10,
yticks = [1, 10, 100],
xticks = 0:2:24,
title = "Mean concentration profile for each dose level",
),
)

# There are many more options:
Expand All @@ -71,8 +71,8 @@ draw(plt_iv; palettes = (; color = [:navyblue, :limegreen, :coral]))
base_plt = data(demographics_df) * mapping(:AGE => "Age (years)", :eGFR => "eGFR")

visuals = (
visual(Scatter; color = :grey, markersize = 10, strokewidth = 0.5) +
AlgebraOfGraphics.linear() * visual(; color = :navyblue, linestyle = :dash)
visual(Scatter; color = :grey, markersize = 10, strokewidth = 0.5) +
AlgebraOfGraphics.linear() * visual(; color = :navyblue, linestyle = :dash)
)

plt_reg = base_plt * visuals
Expand All @@ -96,13 +96,13 @@ visual(Scatter) |> draw
sex_renamer = renamer(0 => "Female", 1 => "Male")

plt_rename =
data(demographics_df) *
mapping(
:AGE,
:WEIGHT;
color = :ISMALE => sex_renamer => "Sex", # nonnumeric is no longer needed
) *
visual(Scatter)
data(demographics_df) *
mapping(
:AGE,
:WEIGHT;
color = :ISMALE => sex_renamer => "Sex", # nonnumeric is no longer needed
) *
visual(Scatter)
draw(plt_rename)

## Tip: you can customize the legend
Expand All @@ -111,9 +111,9 @@ draw(plt_rename; legend = (; position = :top, markersize = 15, titleposition = :
## It also works for faceting
data(demographics_df) *
mapping(
:AGE,
:WEIGHT;
col = :ISMALE => sex_renamer => "Sex", # Works for col, row, layout
:AGE,
:WEIGHT;
col = :ISMALE => sex_renamer => "Sex", # Works for col, row, layout
) *
visual(Scatter) |> draw

Expand All @@ -122,6 +122,6 @@ draw(plt_subjects) # Somewhat small

## Increase the resolution
draw(plt_subjects; figure = (;
resolution = (2000, 1500),
fontsize = 28, # We often need to increase the font size when we increase the resolution
resolution = (2000, 1500),
fontsize = 28, # We often need to increase the font size when we increase the resolution
))

0 comments on commit 9bf90b0

Please sign in to comment.