Skip to content

Commit d1a8350

Browse files
committed
examples fixed
1 parent ec3f963 commit d1a8350

File tree

6 files changed

+39
-569
lines changed

6 files changed

+39
-569
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
1818
KernelDensity = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
1919
Loess = "4345ca2d-374a-55d4-8d30-97f9976e7612"
2020
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
21+
PalmerPenguins = "8b842266-38fa-440a-9b57-31493939ab85"
2122
Parquet2 = "98572fba-bba0-415d-956f-fa77e587d26d"
2223
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
2324
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
@@ -44,6 +45,7 @@ Images = "0.26.2"
4445
KernelDensity = "0.6"
4546
Loess = "0.6"
4647
Makie = "0.24"
48+
PalmerPenguins = "0.1.4"
4749
Parquet2 = "0.2"
4850
PooledArrays = "1.4"
4951
RDatasets = "0.7.7"

docs/examples/geoms/geom_errorbars.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ using Statistics
4545

4646
penguins = dropmissing(DataFrame(PalmerPenguins.load()));
4747

48-
# First, create a summary dataset with means and standard errors:
48+
# First, create a summary dataset with means and standard deviations:
4949

5050
df = @chain penguins begin
5151
@group_by(species)
5252
@summarize(
5353
mean_bill = mean(bill_length_mm),
54-
se_bill = std(bill_length_mm) / sqrt(n())
54+
sd_bill = std(bill_length_mm),
55+
n = n()
56+
)
57+
@mutate(
58+
se_bill = sd_bill / sqrt(n)
5559
)
5660
@mutate(
5761
lower = mean_bill - 1.96 * se_bill,
@@ -87,7 +91,11 @@ df_h = @chain penguins begin
8791
@group_by(species)
8892
@summarize(
8993
mean_bill = mean(bill_length_mm),
90-
se_bill = std(bill_length_mm) / sqrt(n())
94+
sd_bill = std(bill_length_mm),
95+
n = n()
96+
)
97+
@mutate(
98+
se_bill = sd_bill / sqrt(n)
9199
)
92100
@mutate(
93101
lower = mean_bill - 1.96 * se_bill,
@@ -101,10 +109,14 @@ ggplot(df_h, @aes(y = species, xmin = lower, xmax = upper)) +
101109
# Colored error bars by group:
102110

103111
df_grouped = @chain penguins begin
104-
@group_by(species, sex)
112+
@group_by(species)
105113
@summarize(
106114
mean_bill = mean(bill_length_mm),
107-
se_bill = std(bill_length_mm) / sqrt(n())
115+
sd_bill = std(bill_length_mm),
116+
n = n()
117+
)
118+
@mutate(
119+
se_bill = sd_bill / sqrt(n)
108120
)
109121
@mutate(
110122
lower = mean_bill - 1.96 * se_bill,

docs/examples/geoms/geom_lines.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ggplot(economics, @aes(x = Date, y = Unemploy)) +
6565

6666
# Use the `color` aesthetic to draw multiple lines for different groups:
6767

68-
economics_long = @pivot_longer(economics, POP:Unemploy)
68+
economics_long = @pivot_longer(economics, Pop:Unemploy)
6969

7070
ggplot(economics_long, @aes(x = Date, y = value, color = variable)) +
7171
geom_line()

docs/examples/geoms/geom_violin.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ ggplot(penguins, @aes(x = species, y = bill_length_mm, fill = sex, dodge = sex))
7979
# Add stroke color and adjust transparency:
8080

8181
ggplot(penguins, @aes(x = species, y = bill_length_mm)) +
82-
geom_violin(color = :steelblue, strokecolor = :black, strokewidth = 2, alpha = 0.7)
82+
geom_violin(color = :steelblue, strokecolor = :black, strokewidth = 2)
8383

8484
# Different fill colors:
8585

8686
ggplot(penguins, @aes(x = species, y = bill_length_mm, fill = species)) +
87-
geom_violin(alpha = 0.8, strokecolor = :black, strokewidth = 1)
87+
geom_violin(strokecolor = :black, strokewidth = 1)
8888

8989
# ## Combining with Other Geoms
9090

9191
# Combine violin with boxplot for more information:
9292

9393
ggplot(penguins, @aes(x = species, y = bill_length_mm)) +
94-
geom_violin(alpha = 0.5) +
94+
geom_violin() +
9595
geom_boxplot(width = 0.2, alpha = 0.8)
9696

9797
# Add individual data points:
@@ -103,39 +103,39 @@ ggplot(penguins, @aes(x = species, y = bill_length_mm)) +
103103
# Use jittered points for better visibility:
104104

105105
ggplot(penguins, @aes(x = species, y = bill_length_mm)) +
106-
geom_violin(alpha = 0.5, strokecolor = :black) +
106+
geom_violin(strokecolor = :black) +
107107
geom_jitter(alpha = 0.3, width = 0.1)
108108

109109
# ## Comparing Multiple Variables
110110

111111
# Compare distributions across different measurements:
112112

113113
ggplot(penguins, @aes(x = species, y = flipper_length_mm)) +
114-
geom_violin(alpha = 0.7) +
114+
geom_violin() +
115115
labs(title = "Flipper Length by Species")
116116

117117
#-
118118

119119
ggplot(penguins, @aes(x = species, y = body_mass_g)) +
120-
geom_violin(alpha = 0.7) +
120+
geom_violin() +
121121
labs(title = "Body Mass by Species")
122122

123123
# ## Using with Facets
124124

125125
# Use faceting to compare distributions across multiple categorical variables:
126126

127127
ggplot(penguins, @aes(x = species, y = bill_length_mm)) +
128-
geom_violin(alpha = 0.7) +
128+
geom_violin() +
129129
facet_wrap(:sex)
130130

131131
# ## Violin vs Density Comparison
132132

133133
# Violin plots are essentially mirrored density plots. Compare:
134134

135135
ggplot(penguins, @aes(x = bill_length_mm, fill = species)) +
136-
geom_density(alpha = 0.5)
136+
geom_density()
137137

138138
# The violin plot shows the same information but in a compact, comparative format:
139139

140140
ggplot(penguins, @aes(x = species, y = bill_length_mm, fill = species)) +
141-
geom_violin(alpha = 0.7)
141+
geom_violin()

test/penguin_points.png

119 KB
Loading

0 commit comments

Comments
 (0)