diff --git a/altdoc/pkgdown.yml b/altdoc/pkgdown.yml index 534a46ad..33958252 100644 --- a/altdoc/pkgdown.yml +++ b/altdoc/pkgdown.yml @@ -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 diff --git a/vignettes/gallery.qmd b/vignettes/gallery.qmd index 487ce38a..174739a6 100644 --- a/vignettes/gallery.qmd +++ b/vignettes/gallery.qmd @@ -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} @@ -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 @@ -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} @@ -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} @@ -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} @@ -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 diff --git a/vignettes/gallery_figs/add-ablines.R b/vignettes/gallery_figs/add-ablines.R index 16f29303..49c477f2 100644 --- a/vignettes/gallery_figs/add-ablines.R +++ b/vignettes/gallery_figs/add-ablines.R @@ -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) diff --git a/vignettes/gallery_figs/add-text-mtcars.R b/vignettes/gallery_figs/add-text-mtcars.R index bc9bdc84..b9461205 100644 --- a/vignettes/gallery_figs/add-text-mtcars.R +++ b/vignettes/gallery_figs/add-text-mtcars.R @@ -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) + diff --git a/vignettes/gallery_figs/points-quakes-hershey.R b/vignettes/gallery_figs/bubble-quakes.R similarity index 54% rename from vignettes/gallery_figs/points-quakes-hershey.R rename to vignettes/gallery_figs/bubble-quakes.R index 95008f9f..82cd1f4d 100644 --- a/vignettes/gallery_figs/points-quakes-hershey.R +++ b/vignettes/gallery_figs/bubble-quakes.R @@ -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 ) -) +) \ No newline at end of file diff --git a/vignettes/gallery_figs/errorbar-mtcars.R b/vignettes/gallery_figs/coefplot-mtcars.R similarity index 91% rename from vignettes/gallery_figs/errorbar-mtcars.R rename to vignettes/gallery_figs/coefplot-mtcars.R index 4711a2b7..6da7421d 100644 --- a/vignettes/gallery_figs/errorbar-mtcars.R +++ b/vignettes/gallery_figs/coefplot-mtcars.R @@ -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), diff --git a/vignettes/gallery_figs/direct-labels-aq.R b/vignettes/gallery_figs/direct-labels-aq.R index 93af6278..c3b1c0a6 100644 --- a/vignettes/gallery_figs/direct-labels-aq.R +++ b/vignettes/gallery_figs/direct-labels-aq.R @@ -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", diff --git a/vignettes/gallery_figs/likert.R b/vignettes/gallery_figs/likert.R new file mode 100644 index 00000000..6823bbbe --- /dev/null +++ b/vignettes/gallery_figs/likert.R @@ -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 diff --git a/vignettes/gallery_figs/pirate-iris.R b/vignettes/gallery_figs/pirate-iris.R new file mode 100644 index 00000000..1ae6e6bf --- /dev/null +++ b/vignettes/gallery_figs/pirate-iris.R @@ -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' +) \ No newline at end of file diff --git a/vignettes/gallery_figs/points-iris-better.R b/vignettes/gallery_figs/points-iris-better.R index 23e9d18a..cb07a363 100644 --- a/vignettes/gallery_figs/points-iris-better.R +++ b/vignettes/gallery_figs/points-iris-better.R @@ -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" ) diff --git a/vignettes/gallery_figs/polygons.R b/vignettes/gallery_figs/polygons.R index 0369ce73..0f9ad61d 100644 --- a/vignettes/gallery_figs/polygons.R +++ b/vignettes/gallery_figs/polygons.R @@ -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' ) diff --git a/vignettes/gallery_figs/simpsons-paradox.R b/vignettes/gallery_figs/simpsons-paradox.R new file mode 100644 index 00000000..73a5ff73 --- /dev/null +++ b/vignettes/gallery_figs/simpsons-paradox.R @@ -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") diff --git a/vignettes/gallery_figs/spaghetti-aq.R b/vignettes/gallery_figs/spaghetti-aq.R new file mode 100644 index 00000000..553216a3 --- /dev/null +++ b/vignettes/gallery_figs/spaghetti-aq.R @@ -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 +)