Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions altdoc/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
altdoc: 0.7.2
pandoc: 3.9.0.2
pandoc: '3.10'
pkgdown: 2.1.3
pkgdown_sha: ~
last_built: 2026-06-04T16:46:48+0000
last_built: 2026-06-18T16:00:18+0000
urls:
reference: https://grantmcdermott.com/tinyplot/man
article: https://grantmcdermott.com/tinyplot/vignettes
56 changes: 42 additions & 14 deletions vignettes/gallery.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ Click on a plot to get the link to its code.
```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/add-points-rug-faithful.R){target='_blank'}"
#| file: "gallery_figs/add-points-rug-faithful.R"
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/bubble-quakes.R){target='_blank'}"
#| file: "gallery_figs/bubble-quakes.R"
```

```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/spaghetti-aq.R){target='_blank'}"
#| file: "gallery_figs/spaghetti-aq.R"
```

```{r}
Expand All @@ -69,6 +76,13 @@ Click on a plot to get the link to its code.
#| file: "gallery_figs/direct-labels-aq.R"
```

```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/hist-by-penguins.R){target='_blank'}"
#| file: "gallery_figs/hist-by-penguins.R"
```

```{r}
#| lightbox:
#| group: r-graph
Expand All @@ -79,8 +93,8 @@ Click on a plot to get the link to its code.
```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/hist-by-penguins.R){target='_blank'}"
#| file: "gallery_figs/hist-by-penguins.R"
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/likert.R){target='_blank'}"
#| file: "gallery_figs/likert.R"
```

```{r}
Expand All @@ -93,22 +107,29 @@ Click on a plot to get the link to its code.
```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/points-quakes-hershey.R){target='_blank'}"
#| file: "gallery_figs/points-quakes-hershey.R"
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/coefplot-mtcars.R){target='_blank'}"
#| file: "gallery_figs/coefplot-mtcars.R"
```

```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/errorbar-mtcars.R){target='_blank'}"
#| file: "gallery_figs/errorbar-mtcars.R"
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/simpsons-paradox.R){target='_blank'}"
#| file: "gallery_figs/simpsons-paradox.R"
```

```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/rect-by.R){target='_blank'}"
#| file: "gallery_figs/rect-by.R"
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/add-ablines.R){target='_blank'}"
#| file: "gallery_figs/add-ablines.R"
```

```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/add-points-rug-faithful.R){target='_blank'}"
#| file: "gallery_figs/add-points-rug-faithful.R"
```

```{r}
Expand All @@ -121,15 +142,15 @@ Click on a plot to get the link to its code.
```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/add-ablines.R){target='_blank'}"
#| file: "gallery_figs/add-ablines.R"
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/pirate-iris.R){target='_blank'}"
#| file: "gallery_figs/pirate-iris.R"
```

```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/density-part-shading.R){target='_blank'}"
#| file: "gallery_figs/density-part-shading.R"
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/rect-by.R){target='_blank'}"
#| file: "gallery_figs/rect-by.R"
```

```{r}
Expand All @@ -139,6 +160,13 @@ Click on a plot to get the link to its code.
#| file: "gallery_figs/polygons.R"
```

```{r}
#| lightbox:
#| group: r-graph
#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/density-part-shading.R){target='_blank'}"
#| file: "gallery_figs/density-part-shading.R"
```

```{r}
#| lightbox:
#| group: r-graph
Expand Down
8 changes: 4 additions & 4 deletions vignettes/gallery_figs/add-ablines.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
library("tinyplot")

tinyplot(mpg ~ hp | cyl, facet = "by", data = mtcars,
legend = FALSE,
theme = "classic",
legend = FALSE, cex = 2, alpha = 0.6,
theme = list("classic", facet.bg = "gray95"),
main = "mtcars: Mileage vs horsepower",
sub = "Faceted by no. of cylinders",
cap = "Note: Dotted lines denote means")
tinyplot_add(type = type_hline(with(mtcars, tapply(mpg, cyl, mean))), lty = 2)
tinyplot_add(type = type_vline(with(mtcars, tapply(hp, cyl, mean))), lty = 2)
tinyplot_add(type = type_hline(with(mtcars, tapply(mpg, cyl, mean))), lty = 2, lwd = 1.5)
tinyplot_add(type = type_vline(with(mtcars, tapply(hp, cyl, mean))), lty = 2, lwd = 1.5)
48 changes: 37 additions & 11 deletions vignettes/gallery_figs/add-text-mtcars.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
library("tinyplot")

mtcars2 = within(
mtcars, {
make = sub(" .*", "", row.names(mtcars))
model = sub("^\\S+\\s+", "", row.names(mtcars))
merc = factor(ifelse(make == "Merc", "Mercedes", "Other"), levels = c("Other", "Mercedes"))
}
)

plt(
mpg ~ hp | factor(cyl),
data = mtcars,
legend = list("topright!", bty = "o"),
theme = "classic"
)
plt_add(type = type_text(
labels = row.names(mtcars),
adj = -0.05,
srt = 15,
xpd = NA
))
qsec ~ mpg | merc,
data = mtcars2,
legend = list(title = NULL),
ylab = "1/4 mile time (s)",
xlab = "Miles per gallon",
main = "Performance vs efficiency",
sub = "Mercedes vs the rest",
cap = "Notes: Model numbers highlighted in text",
theme = list("web", palette.qualitative = c("#0FCFC0", "#F79CD4"))
)
plt_add(
type = "text", labels = mtcars2$model, repel = TRUE, xpd = NA, pos = 4,
alpha = 0.3
)
plt_add(
data = subset(mtcars2, make=="Merc")
)
plt_add(
data = subset(mtcars2, make=="Merc"),
type = "text", labels = subset(mtcars2, make == "Merc")$model,
repel = TRUE, xpd = NA, pos = 4, font = 2
)

# optional annotations
arrows(12, 19, 12, 23, length = 0.1, angle = 20, col = "darkgrey", xpd = NA)
text(12, mean(c(19, 23)), "slower", srt = 90, adj = c(0.5, 1.5), col = "darkgrey", font = 3)
arrows(24, 15, 34.5, 15, length = 0.1, angle = 20, col = "darkgrey", xpd = NA)
text(mean(c(24, 34.5)), 15, "thriftier", adj = c(0.5, -1), col = "darkgrey", font = 3)

Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
library(tinyplot)

magnitude = quakes$mag
plt(
lat ~ long | depth, data = quakes,
cex = magnitude, clim = c(0.5, 4.5),
col = "#3D3532",
fill = 0.7, pch = 21,
main = "Earthquakes off Fiji",
xlab = "Longitutde",
ylab = "Latitude",
cap = "Data courtesy of the Harvard PRIM-H project",
palette = "mako",
sub = "Data courtesy of the Harvard PRIM-H project",
palette = "sunsetdark",
# custom ephemeral theme
theme = list(
"dynamic",
bty = "n",
bg = "#E0D9D2",# "#F7F3EF",
bg = "#E0D9D2",
cex = 1.2, cex.main = 1.5, cex.lab = 1.2,
col = "#3D3532",
family = "HersheyScript",
grid = TRUE, grid.col = "gray95"
grid = TRUE, grid.col = "gray70",
lwd = 0.5
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tinyplot(
type = "errorbar",
xlab = NA, ylab = "Estimate",
flip = TRUE,
draw = abline(v = 0, lty = 2, col = "grey50"),
draw = abline(v = 0, lty = 2, col = "hotpink"),
main = "Coefficient plot",
sub = "Determinants of fuel efficiency",
cap = expression(Model: mpg == beta[0] + beta[1] %.% wt + beta[2] %.% am + beta[3] %.% wt %.% am),
Expand Down
2 changes: 1 addition & 1 deletion vignettes/gallery_figs/direct-labels-aq.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library(tinyplot)
aq = airquality
aq$Month = factor(month.name[aq$Month], levels = month.name[5:9])

tinyplot(
plt(
Temp ~ Day | Month,
data = aq,
type = "l",
Expand Down
29 changes: 29 additions & 0 deletions vignettes/gallery_figs/likert.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library(tinyplot)

# construct fake likert data
lik = expand.grid(
question = c("Pay", "Workload", "Manager", "Culture"),
response = c("Strong disagree", "Disagree", "Agree", "Strong agree", "Unsure")
)
lik$response = factor(lik$response, levels = unique(lik$response))
lik$share = c( # proportions summing to 1 within each question
.10, .25, .05, .15,
.20, .30, .15, .20,
.35, .20, .40, .30,
.25, .15, .35, .20,
.10, .10, .05, .15
)

# diverging palette: reds (disagree) -> blues (agree), grey for "Unsure"
pal = c("#b2182b", "#ef8a62", "#67a9cf", "#2166ac", "grey")

plt(
share ~ question | response, data = lik,
type = "barplot", center = TRUE, offset = "Unsure",
flip = TRUE, xlab = NA, ylab = NA, yaxl = "percent",
legend = list("top!", title = NULL),
theme = list("clean2", palette.qualitative = pal),
main = "Likert example with \"Unsure\" category offset"
)
plt_add(type = "vline")
# plt_add(type = "vline", v = 1, lty = 2) ## optional
28 changes: 28 additions & 0 deletions vignettes/gallery_figs/pirate-iris.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
library(tinyplot)

# Register a custom "pirate" theme that builds on top of "clean"
tinytheme_register(
"pirate",
theme = "clean",
family = "HersheyScript",
bg = "#f5e6c8", fg = "#3b2209",
cex.lab = 1.5, cex.main = 1.5, cex.sub = 1.2,
col = "#3b2209", col.axis = "#5c3a1e", col.cap = "#7a5230",
col.lab = "#3b2209", col.main = "#1a0f04", col.sub = "#7a5230",
grid = TRUE, grid.col = "#c9a96e", grid.lty = "dotted",
facet.bg = "#e8d4a8", facet.border = "#5c3a1e",
pch = 4,
palette.qualitative = c(
"#8b0000", "#1a5276", "#196f3d", "#7d6608",
"#6c3483", "#a04000", "#1b4f72", "#145a32"
)
)

# Use it ephemerally
plt(
Sepal.Length ~ Petal.Length | Species, iris,
main = 'Avast, me hearties!',
sub = 'Here be a "pirate" theme',
cap = '"x" marks the spot',
theme = 'pirate'
)
5 changes: 1 addition & 4 deletions vignettes/gallery_figs/points-iris-better.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ library(tinyplot)
tinyplot(
Sepal.Length ~ Petal.Length | Species,
data = iris,
palette = "dark",
pch = 16,
grid = TRUE,
frame = FALSE,
theme = 'float', grid = TRUE,
main = "A more exciting scatterplot"
)
3 changes: 2 additions & 1 deletion vignettes/gallery_figs/polygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ plt(
x = 1:9,
y = c(2,1,2,1,NA,2,1,2,1),
type = type_polygon(density = c(10, 20)),
theme = 'dynamic'
lwd = 2,
theme = 'dark'
)
14 changes: 14 additions & 0 deletions vignettes/gallery_figs/simpsons-paradox.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
library(tinyplot)

plt(
bill_dep ~ bill_len | species, data = penguins,
pch = c(21, 24, 22), fill = 0.6, cex = 1.2,
main = "Bill dimensions for different penguin species",
sub = "Illustration of Simpson's paradox",
cap = "Notes: Lines show OLS fit for species-specific (solid) vs. pooled (dotted grey) samples.",
xlab = "Bill length (mm)", ylab = "Bill depth (mm)",
legend = list("bottomright", title = "Species", bty = "o", lty = 1),
theme = list("minimal", palette.qualitative = c("darkorange", "purple", "cyan4"))
)
plt_add(type = type_lm(se = FALSE), lwd = 2)
plt_add(bill_dep ~ bill_len, type = type_lm(se = FALSE), lwd = 2, lty = 2, col = "darkgray")
13 changes: 13 additions & 0 deletions vignettes/gallery_figs/spaghetti-aq.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library(tinyplot)

aq = airquality
aq$Month = factor(month.name[aq$Month], levels = month.name[5:9])

plt(
Temp ~ Day | Month, aq, facet = "by", lwd = 3, type = "l",
legend = FALSE,
draw = plt_add(col = "grey", facet = NULL, lwd = 1),
main = "Temperatures by month",
sub = "Sometimes, spaghetti plots are the right choice",
theme = "float", ylim = c(50, 100), frame = FALSE
)
Loading