Skip to content

Commit aa82805

Browse files
staredclaude
andcommitted
Replace mtcars examples with iris dataset and improve visualizations
- Replace all mtcars examples with iris-based visualizations - Add iris petal scatter plot as default example (with default colors) - Create simplified kawaii visualization with better readability - Add 2x2 violin plot panels for iris measurements (without boxplot) - Remove startup funding and global warming examples - Update CSV template with clearer instructions - Add tidyr to essential packages for data reshaping 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 42927ed commit aa82805

File tree

2 files changed

+79
-157
lines changed

2 files changed

+79
-157
lines changed

src/data/examples.ts

Lines changed: 78 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -2,93 +2,94 @@ import type { RExample } from '@/types'
22

33
export const examples: RExample[] = [
44
{
5-
id: 'car-weight-mpg',
6-
title: 'Car weight vs fuel efficiency',
7-
description: 'Heavier cars consume more fuel - classic automotive relationship',
5+
id: 'iris-petal-scatter',
6+
title: 'Iris petal dimensions',
7+
description: 'Explore the relationship between petal length and width across iris species',
88
code: `library(ggplot2)
99
10-
# Load built-in R dataset about car characteristics
11-
# Contains data on 32 car models from 1973-74
12-
data(mtcars)
13-
ggplot(mtcars, aes(x = wt, y = mpg)) +
14-
geom_point() +
15-
labs(title = "Car Weight vs Fuel Efficiency",
16-
x = "Weight (1000 lbs)",
17-
y = "Miles per Gallon") +
18-
theme_minimal()`,
19-
},
20-
{
21-
id: 'cylinders-matter',
22-
title: 'Why cylinder count matters',
23-
description: 'Engine cylinders affect both weight and fuel efficiency',
24-
code: `library(ggplot2)
10+
# Load the classic iris dataset
11+
# Contains measurements for 150 iris flowers from 3 species
12+
data(iris)
2513
26-
# Load built-in dataset
27-
# Visualize multiple variables: weight, mpg, and cylinder count
28-
data(mtcars)
29-
ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
30-
geom_point(size = 3, alpha = 0.7) +
31-
geom_smooth(method = "lm", se = FALSE) +
32-
scale_color_manual(values = c("4" = "#E31A1C", "6" = "#1F78B4", "8" = "#33A02C")) +
33-
labs(title = "Car Weight vs MPG by Cylinder Count",
34-
x = "Weight (1000 lbs)",
35-
y = "Miles per Gallon",
36-
color = "Cylinders") +
14+
# Create scatter plot of petal dimensions
15+
ggplot(iris, aes(x = Petal.Length, y = Petal.Width, color = Species)) +
16+
geom_point(size = 3, alpha = 0.8) +
17+
labs(title = "Iris Petal Dimensions by Species",
18+
x = "Petal Length (cm)",
19+
y = "Petal Width (cm)") +
3720
theme_minimal() +
3821
theme(legend.position = "bottom")`,
3922
},
4023
{
41-
id: 'efficient-cars-only',
42-
title: 'Focus on efficient cars',
43-
description: 'What makes fuel-efficient cars special?',
44-
code: `library(dplyr)
45-
library(ggplot2)
24+
id: 'kawaii-iris',
25+
title: 'Kawaii-style iris visualization',
26+
description: 'A playful, pastel visualization of iris sepal dimensions',
27+
code: `library(ggplot2)
4628
47-
# Load built-in dataset
48-
# Filter cars with good fuel efficiency and summarize by cylinders
49-
data(mtcars)
50-
mtcars_summary <- mtcars %>%
51-
filter(mpg > 20) %>%
52-
group_by(cyl) %>%
53-
summarize(
54-
avg_mpg = mean(mpg),
55-
count = n(),
56-
.groups = 'drop'
57-
)
29+
# Load iris dataset for a cute visualization
30+
data(iris)
5831
59-
# Visualize the summary
60-
ggplot(mtcars_summary, aes(x = factor(cyl), y = avg_mpg)) +
61-
geom_col(fill = "steelblue") +
62-
geom_text(aes(label = paste("n =", count)), vjust = -0.5) +
63-
labs(title = "Average MPG by Cylinder Count (Efficient Cars Only)",
64-
x = "Number of Cylinders",
65-
y = "Average MPG") +
66-
theme_minimal()`,
32+
# Create a simple kawaii-style plot
33+
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
34+
# Use flower-shaped points
35+
geom_point(size = 8, shape = 8, stroke = 2, alpha = 0.9) +
36+
# Simple pastel kawaii colors
37+
scale_color_manual(values = c("setosa" = "#FF69B4", # Hot pink
38+
"versicolor" = "#DDA0DD", # Plum
39+
"virginica" = "#87CEEB")) + # Sky blue
40+
# Add cute title and labels
41+
labs(title = "✿ Kawaii Iris Garden ✿",
42+
x = "Sepal Length ♡",
43+
y = "Sepal Width ♡") +
44+
# Simple kawaii theme
45+
theme_minimal() +
46+
theme(
47+
plot.background = element_rect(fill = "#FFF0F5", color = NA),
48+
panel.background = element_rect(fill = "#FFFAFA", color = NA),
49+
panel.grid = element_line(color = "#FFE0F0", size = 0.3),
50+
text = element_text(color = "#FF1493"),
51+
plot.title = element_text(size = 18, face = "bold", hjust = 0.5),
52+
legend.position = "bottom",
53+
legend.background = element_blank(),
54+
legend.key = element_blank(),
55+
axis.text = element_text(color = "#FF69B4"),
56+
axis.title = element_text(face = "bold")
57+
)`,
6758
},
6859
{
69-
id: 'manual-vs-automatic',
70-
title: 'Manual vs automatic transmission',
71-
description: 'Do manual transmissions really save fuel?',
72-
code: `library(dplyr)
73-
library(ggplot2)
60+
id: 'iris-violin-panels',
61+
title: 'Iris measurements distribution',
62+
description: 'Violin plots showing distribution of all iris measurements in a 2x2 panel',
63+
code: `library(ggplot2)
64+
library(tidyr)
7465
75-
# Load built-in dataset
76-
# Create grouped bar chart showing gears vs transmission type
77-
data(mtcars)
78-
gear_summary <- mtcars %>%
79-
group_by(gear, am) %>%
80-
summarize(count = n(), .groups = 'drop') %>%
81-
mutate(transmission = ifelse(am == 0, "Automatic", "Manual"))
66+
# Load iris dataset
67+
data(iris)
8268
83-
ggplot(gear_summary, aes(x = factor(gear), y = count, fill = transmission)) +
84-
geom_col(position = "dodge") +
85-
scale_fill_manual(values = c("Automatic" = "#FF7F00", "Manual" = "#1F78B4")) +
86-
labs(title = "Cars by Gear Count and Transmission Type",
87-
x = "Number of Gears",
88-
y = "Count",
89-
fill = "Transmission") +
69+
# Reshape data to long format for faceting
70+
iris_long <- iris %>%
71+
pivot_longer(cols = -Species,
72+
names_to = "Measurement",
73+
values_to = "Value")
74+
75+
# Create 2x2 panel of violin plots
76+
ggplot(iris_long, aes(x = Species, y = Value, fill = Species)) +
77+
geom_violin(alpha = 0.7, scale = "width", trim = FALSE) +
78+
facet_wrap(~ Measurement, scales = "free_y", ncol = 2) +
79+
scale_fill_manual(values = c("setosa" = "#FF7F50",
80+
"versicolor" = "#9370DB",
81+
"virginica" = "#20B2AA")) +
82+
labs(title = "Distribution of Iris Measurements",
83+
subtitle = "Violin plots showing the distribution and density of each measurement",
84+
x = NULL,
85+
y = "Measurement (cm)") +
9086
theme_minimal() +
91-
theme(legend.position = "bottom")`,
87+
theme(
88+
legend.position = "none",
89+
strip.text = element_text(face = "bold", size = 12),
90+
strip.background = element_rect(fill = "#F0F0F0", color = NA),
91+
panel.spacing = unit(1, "lines")
92+
)`,
9293
},
9394
{
9495
id: 'metal-bands-happiness',
@@ -113,93 +114,14 @@ ggplot(data, aes(x = Metal.bands.per.capita, y = Score, label = Country.or.regio
113114
caption = "Read more: https://p.migdal.pl/blog/2023/01/metal-bands-happiness-correlation") +
114115
theme_minimal()`,
115116
},
116-
{
117-
id: 'global-warming',
118-
title: 'Global warming evidence',
119-
description: 'Temperature rise over the past decades',
120-
csvUrl: '/global_temperature.csv',
121-
code: `library(ggplot2)
122-
123-
# Load global temperature time series data
124-
data <- read.csv("/tmp/global_temperature.csv", stringsAsFactors = FALSE)
125-
126-
# Create time series visualization with trend line
127-
ggplot(data, aes(x = year)) +
128-
geom_line(aes(y = temperature_celsius), color = "#e74c3c", size = 1.5) +
129-
geom_point(aes(y = temperature_celsius), color = "#c0392b", size = 2) +
130-
geom_smooth(aes(y = temperature_celsius), method = "loess", se = TRUE,
131-
color = "#e74c3c", alpha = 0.2) +
132-
labs(title = "Global Temperature Trend (2000-2020)",
133-
x = "Year",
134-
y = "Temperature (°C)",
135-
caption = "Data: Global temperature measurements") +
136-
theme_minimal()`,
137-
},
138-
{
139-
id: 'startup-gold-rush',
140-
title: 'The startup gold rush',
141-
description: 'Which sectors attract the most venture capital?',
142-
csvUrl: '/startup_funding.csv',
143-
code: `library(dplyr)
144-
library(ggplot2)
145-
146-
# Load startup funding data
147-
data <- read.csv("/tmp/startup_funding.csv", stringsAsFactors = FALSE)
148-
149-
# Explore the data structure
150-
head(data)
151-
152-
# Summarize funding by sector
153-
sector_summary <- data %>%
154-
group_by(sector) %>%
155-
summarise(
156-
total_funding = sum(funding_amount_usd),
157-
avg_funding = mean(funding_amount_usd),
158-
count = n(),
159-
.groups = 'drop'
160-
) %>%
161-
arrange(desc(total_funding))
162-
163-
print(sector_summary)
164-
165-
# Create horizontal bar chart
166-
ggplot(sector_summary, aes(x = reorder(sector, total_funding),
167-
y = total_funding / 1e6, fill = sector)) +
168-
geom_col(show.legend = FALSE) +
169-
coord_flip() +
170-
labs(title = "Total Startup Funding by Sector",
171-
x = "Sector",
172-
y = "Funding Amount (Million USD)") +
173-
theme_minimal()`,
174-
},
175117
{
176118
id: 'custom-csv-template',
177119
title: 'Your CSV template',
178120
description: 'Starting point for analyzing your own data',
179-
code: `library(dplyr)
180-
library(ggplot2)
181-
182-
# TO USE YOUR OWN DATA:
183-
# 1. Upload your CSV file using the interface above
184-
# 2. Replace the filename below with your actual filename
185-
# data <- read.csv("/tmp/your_filename.csv", stringsAsFactors = FALSE)
186-
187-
# For demonstration, load iris - built-in dataset with flower measurements
188-
# iris contains 150 observations of 3 species with 4 measurements each
189-
data(iris)
190-
data <- iris
191-
192-
# Explore your data structure
193-
str(data) # Show data types and structure
194-
head(data) # Show first 6 rows
195-
summary(data) # Show statistical summary
121+
code: `library(ggplot2)
196122
197-
# Example scatter plot - modify based on your columns
198-
ggplot(data, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
199-
geom_point(size = 3, alpha = 0.7) +
200-
labs(title = "Your Data Visualization",
201-
x = "X Variable",
202-
y = "Y Variable") +
203-
theme_minimal()`,
123+
# Upload your CSV file using the button above
124+
# Then change "your_filename.csv" to your actual filename and press Run
125+
data <- read.csv("/tmp/your_filename.csv", stringsAsFactors = FALSE)`,
204126
},
205127
]

src/webr/storage/package-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class PackageManager {
1212
private versions = new Map<string, string>()
1313

1414
// Essential packages for ggplot2 demos
15-
static readonly ESSENTIALS = ['ggplot2', 'dplyr', 'ggrepel'] as const
15+
static readonly ESSENTIALS = ['ggplot2', 'dplyr', 'ggrepel', 'tidyr'] as const
1616

1717
constructor(private webR: WebR) {}
1818

0 commit comments

Comments
 (0)