Skip to content

Commit 4da5502

Browse files
staredclaude
andcommitted
Add ggrepel support and metal bands vs happiness example
- Install ggrepel package during WebR initialization - Add new example: "Metal bands vs happiness" correlation chart - Includes sample data with 15 countries showing metal bands per capita vs happiness scores - Uses ggrepel for non-overlapping country labels - Features log scale, linear regression line, and proper attribution - Based on analysis from p.migdal.pl blog post 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e0f85a0 commit 4da5502

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/composables/useWebR.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export const useWebR = () => {
3434
shelter = await new webR.Shelter()
3535

3636
// Install required packages
37-
await webR.installPackages(['ggplot2', 'dplyr'])
37+
await webR.installPackages(['ggplot2', 'dplyr', 'ggrepel'])
3838

3939
isReady.value = true
40-
addMessage('success', 'WebR initialized successfully with ggplot2 and dplyr')
40+
addMessage('success', 'WebR initialized successfully with ggplot2, dplyr, and ggrepel')
4141
} catch (error) {
4242
console.error('WebR initialization failed:', error)
4343
addMessage('error', `Failed to initialize WebR: ${error}`)

src/data/examples.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,35 @@ ggplot(dataset, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
106106
theme_minimal() +
107107
theme(legend.position = "bottom")`,
108108
},
109+
{
110+
id: 'metal-bands-happiness',
111+
title: 'Metal bands vs happiness',
112+
description: 'Correlation between metal bands per capita and happiness score by country',
113+
code: `library(ggplot2)
114+
library(ggrepel)
115+
116+
# Note: This example requires the metal_bands_happiness.csv file to be uploaded
117+
# For now, we'll create sample data to demonstrate the visualization
118+
119+
# Sample data (replace with real data when CSV is uploaded)
120+
df <- data.frame(
121+
Country.or.region = c("Finland", "Sweden", "Norway", "Denmark", "Iceland",
122+
"Switzerland", "Netherlands", "Canada", "New Zealand", "Austria",
123+
"Germany", "United Kingdom", "United States", "France", "Spain"),
124+
Metal.bands.per.capita = c(630, 428, 309, 295, 340, 179, 158, 152, 143, 156,
125+
171, 147, 72, 89, 87),
126+
Score = c(7.8, 7.6, 7.5, 7.5, 7.5, 7.5, 7.4, 7.2, 7.2, 7.2,
127+
7.0, 6.9, 6.9, 6.6, 6.4)
128+
)
129+
130+
ggplot(df, aes(x = Metal.bands.per.capita, y = Score, label = Country.or.region)) +
131+
scale_x_log10() +
132+
stat_smooth(method = "lm", linewidth = 0.5, alpha = 0.2) +
133+
geom_point(color = "red", size = 0.5) +
134+
geom_text_repel(size = 3, point.size = 0.5, segment.alpha = 0.5, segment.color = "red") +
135+
xlab("Metal bands per 1M people") +
136+
ylab("Average happiness score") +
137+
labs(caption = "Data sources: Enc. Metallum (2016), after Jakub Marian; World Happiness Report (2022). Chart by Piotr Migdał, p.migdal.pl, CC-BY.") +
138+
theme_minimal()`,
139+
},
109140
]

0 commit comments

Comments
 (0)