diff --git a/vignettes/gallery.qmd b/vignettes/gallery.qmd index 54a62caa..2449a5f6 100644 --- a/vignettes/gallery.qmd +++ b/vignettes/gallery.qmd @@ -22,108 +22,99 @@ 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/gallery_01.R){target='_blank'}" -#| file: "gallery_figs/gallery_01.R" +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/points-by-iris.R){target='_blank'}" +#| file: "gallery_figs/points-by-iris.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_02.R){target='_blank'}" -#| file: "gallery_figs/gallery_02.R" +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/points-by-facet-iris.R){target='_blank'}" +#| file: "gallery_figs/points-by-facet-iris.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_03.R){target='_blank'}" -#| file: "gallery_figs/gallery_03.R" -#| fig-asp: .5 +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/hist-by-iris.R){target='_blank'}" +#| file: "gallery_figs/hist-by-iris.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_04.R){target='_blank'}" -#| file: "gallery_figs/gallery_04.R" -#| fig-asp: .5 +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/bubble-penguins.R){target='_blank'}" +#| file: "gallery_figs/bubble-penguins.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_05.R){target='_blank'}" -#| file: "gallery_figs/gallery_05.R" +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/spineplot-titanic.R){target='_blank'}" +#| file: "gallery_figs/spineplot-titanic.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_06.R){target='_blank'}" -#| file: "gallery_figs/gallery_06.R" +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/ridge-aq.R){target='_blank'}" +#| file: "gallery_figs/ridge-aq.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_07.R){target='_blank'}" -#| file: "gallery_figs/gallery_07.R" +#| 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} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_08.R){target='_blank'}" -#| file: "gallery_figs/gallery_08.R" +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/errorbar-mtcars.R){target='_blank'}" +#| file: "gallery_figs/errorbar-mtcars.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_09.R){target='_blank'}" -#| file: "gallery_figs/gallery_09.R" +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/polygons.R){target='_blank'}" +#| file: "gallery_figs/polygons.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_10.R){target='_blank'}" -#| file: "gallery_figs/gallery_10.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} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_11.R){target='_blank'}" -#| file: "gallery_figs/gallery_11.R" +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/boxplot-by-penguins.R){target='_blank'}" +#| file: "gallery_figs/boxplot-by-penguins.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_12.R){target='_blank'}" -#| file: "gallery_figs/gallery_12.R" +#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/add-text-mtcars.R){target='_blank'}" +#| file: "gallery_figs/add-text-mtcars.R" ``` ```{r} #| lightbox: #| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_13.R){target='_blank'}" -#| file: "gallery_figs/gallery_13.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/gallery_14.R){target='_blank'}" -#| file: "gallery_figs/gallery_14.R" -``` - -```{r} -#| lightbox: -#| group: r-graph -#| description: "[Code](https://github.com/grantmcdermott/tinyplot/blob/main/vignettes/gallery_figs/gallery_15.R){target='_blank'}" -#| file: "gallery_figs/gallery_15.R" +#| 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" ``` ::: diff --git a/vignettes/gallery_figs/add-ablines.R b/vignettes/gallery_figs/add-ablines.R new file mode 100644 index 00000000..19bcb415 --- /dev/null +++ b/vignettes/gallery_figs/add-ablines.R @@ -0,0 +1,5 @@ +library("tinyplot") + +tinyplot(mpg ~ hp | cyl, facet = "by", data = mtcars) +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) diff --git a/vignettes/gallery_figs/add-lm-iris.R b/vignettes/gallery_figs/add-lm-iris.R new file mode 100644 index 00000000..10d04250 --- /dev/null +++ b/vignettes/gallery_figs/add-lm-iris.R @@ -0,0 +1,8 @@ +library(tinyplot) + +tinyplot( + Sepal.Width ~ Petal.Width | Species, + data = iris, + theme = "ipsum" +) +tinyplot_add(type = "lm") diff --git a/vignettes/gallery_figs/add-points-rug-faithful.R b/vignettes/gallery_figs/add-points-rug-faithful.R new file mode 100644 index 00000000..cb42e91d --- /dev/null +++ b/vignettes/gallery_figs/add-points-rug-faithful.R @@ -0,0 +1,6 @@ +library("tinyplot") +tinyplot(eruptions ~ waiting, data = faithful, type = "lm", + theme = "tufte", palette = c("darkcyan")) +tinyplot_add(type = "p", pch = 21, col = "white", fill = 0.3, cex = 1.5) +tinyplot_add(type = type_rug(jitter = TRUE, amount = 0.3)) +tinyplot_add(type = type_rug(jitter = TRUE, amount = 0.1, side = 2)) diff --git a/vignettes/gallery_figs/add-text-mtcars.R b/vignettes/gallery_figs/add-text-mtcars.R new file mode 100644 index 00000000..bc9bdc84 --- /dev/null +++ b/vignettes/gallery_figs/add-text-mtcars.R @@ -0,0 +1,14 @@ +library("tinyplot") + +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 +)) diff --git a/vignettes/gallery_figs/boxplot-by-penguins.R b/vignettes/gallery_figs/boxplot-by-penguins.R new file mode 100644 index 00000000..ba3b6e82 --- /dev/null +++ b/vignettes/gallery_figs/boxplot-by-penguins.R @@ -0,0 +1,9 @@ +library("tinyplot") + +plt( + body_mass ~ species | sex, data = penguins, + type = type_boxplot(boxwex = 0.6, staplewex = 0, outline = FALSE), + lty = 1, + flip = TRUE, yaxl = ",", + grid = TRUE +) diff --git a/vignettes/gallery_figs/bubble-penguins.R b/vignettes/gallery_figs/bubble-penguins.R new file mode 100644 index 00000000..0f899212 --- /dev/null +++ b/vignettes/gallery_figs/bubble-penguins.R @@ -0,0 +1,14 @@ +library(tinyplot) + +with( + na.omit(penguins), + plt( + y = bill_len, x = bill_dep, by = sex, + facet = species, + cex = body_mass, clim = c(0.5, 4.5), + col = 'white', fill = 0.5, pch = 21, + legend = list(labeller = ","), + type = "p", + theme = "clean2" + ) +) diff --git a/vignettes/gallery_figs/gallery_02.R b/vignettes/gallery_figs/density-by-iris.R similarity index 76% rename from vignettes/gallery_figs/gallery_02.R rename to vignettes/gallery_figs/density-by-iris.R index b7375601..a3e16d41 100644 --- a/vignettes/gallery_figs/gallery_02.R +++ b/vignettes/gallery_figs/density-by-iris.R @@ -6,5 +6,6 @@ tinyplot( type = "density", fill = "by", main = "Distribution of petal lengths", - sub = "Grouped by species" + sub = "Grouped by species", + theme = "bw" ) diff --git a/vignettes/gallery_figs/gallery_15.R b/vignettes/gallery_figs/density-part-shading.R similarity index 100% rename from vignettes/gallery_figs/gallery_15.R rename to vignettes/gallery_figs/density-part-shading.R diff --git a/vignettes/gallery_figs/gallery_06.R b/vignettes/gallery_figs/errorbar-mtcars.R similarity index 57% rename from vignettes/gallery_figs/gallery_06.R rename to vignettes/gallery_figs/errorbar-mtcars.R index 1a166b17..66a11f05 100644 --- a/vignettes/gallery_figs/gallery_06.R +++ b/vignettes/gallery_figs/errorbar-mtcars.R @@ -1,5 +1,4 @@ library(tinyplot) -tinytheme("minimal") # fit a model and extract coefficients mod = lm(mpg ~ wt * factor(am), mtcars) @@ -7,13 +6,11 @@ coefs = data.frame(names(coef(mod)), coef(mod), confint(mod)) colnames(coefs) = c("term", "est", "lwr", "upr") # plot the coefficients with error bars -with( - coefs, - tinyplot( - x = term, y = est, ymin = lwr, ymax = upr, - type = type_errorbar(length = 0.1) - ) +tinyplot( + est ~ term, data = coefs, + ymin = lwr, ymax = upr, + type = "errorbar", + flip = TRUE, + draw = abline(v = 0, lty = 2, col = "grey50"), + theme = "classic" ) - - -tinytheme() # reset theme (optional) \ No newline at end of file diff --git a/vignettes/gallery_figs/gallery_05.R b/vignettes/gallery_figs/gallery_05.R deleted file mode 100644 index 6784411d..00000000 --- a/vignettes/gallery_figs/gallery_05.R +++ /dev/null @@ -1,9 +0,0 @@ -library(tinyplot) -tinytheme("ipsum") - -tinyplot(Sepal.Width ~ Petal.Width | Species, - data = iris, - type = "lm") -tinyplot_add(type = "p", alpha = .2) - -tinytheme() # reset theme (optional) \ No newline at end of file diff --git a/vignettes/gallery_figs/gallery_09.R b/vignettes/gallery_figs/gallery_09.R deleted file mode 100644 index 9045123e..00000000 --- a/vignettes/gallery_figs/gallery_09.R +++ /dev/null @@ -1,6 +0,0 @@ -library("tinyplot") -tinyplot(eruptions ~ waiting, data = faithful, type = "lm") -tinyplot_add(type = type_rug(jitter = TRUE, amount = 0.3)) -tinyplot_add(type = type_rug(jitter = TRUE, amount = 0.1, side = 2)) -tinyplot_add(type = "p") - diff --git a/vignettes/gallery_figs/gallery_10.R b/vignettes/gallery_figs/gallery_10.R deleted file mode 100644 index a935e72c..00000000 --- a/vignettes/gallery_figs/gallery_10.R +++ /dev/null @@ -1,9 +0,0 @@ -library("tinyplot") -tinytheme("bw") -tinyplot( - ~Petal.Width | Species, - type = "histogram", - data = iris -) - -tinytheme() # reset theme (optional) \ No newline at end of file diff --git a/vignettes/gallery_figs/gallery_11.R b/vignettes/gallery_figs/gallery_11.R deleted file mode 100644 index 967c44e7..00000000 --- a/vignettes/gallery_figs/gallery_11.R +++ /dev/null @@ -1,10 +0,0 @@ -library("tinyplot") -tinytheme("tufte") - -tinyplot( - len ~ dose | supp, data = ToothGrowth, lty = 1, - flip = TRUE, - type = type_boxplot(boxwex = 0.6, staplewex = 0, outline = FALSE) -) - -tinytheme() # reset theme (optional) \ No newline at end of file diff --git a/vignettes/gallery_figs/gallery_13.R b/vignettes/gallery_figs/gallery_13.R deleted file mode 100644 index 70122196..00000000 --- a/vignettes/gallery_figs/gallery_13.R +++ /dev/null @@ -1,8 +0,0 @@ -library("tinyplot") - -tinyplot(mpg ~ hp | factor(cyl), - data = mtcars, - type = type_text( - labels = row.names(mtcars), - font = 1, - adj = 0)) diff --git a/vignettes/gallery_figs/gallery_14.R b/vignettes/gallery_figs/gallery_14.R deleted file mode 100644 index 18535f43..00000000 --- a/vignettes/gallery_figs/gallery_14.R +++ /dev/null @@ -1,5 +0,0 @@ -library("tinyplot") - -cols = c("black", "green", "orange") -tinyplot(mpg ~ hp | factor(cyl), facet = ~ factor(cyl), data = mtcars, col = cols) -tinyplot_add(type = type_vline(v = c(100, 150, 200)), lty = 3, lwd = 3) diff --git a/vignettes/gallery_figs/hist-by-iris.R b/vignettes/gallery_figs/hist-by-iris.R new file mode 100644 index 00000000..e0106658 --- /dev/null +++ b/vignettes/gallery_figs/hist-by-iris.R @@ -0,0 +1,11 @@ +library("tinyplot") + +tinyplot( + ~Petal.Length | Species, + data = iris, + type = "histogram", + breaks = 30, + main = "Histogram of petal lengths", + sub = "Grouped by species", + theme = "bw" +) \ No newline at end of file diff --git a/vignettes/gallery_figs/gallery_03.R b/vignettes/gallery_figs/points-by-facet-iris.R similarity index 59% rename from vignettes/gallery_figs/gallery_03.R rename to vignettes/gallery_figs/points-by-facet-iris.R index a580e90b..1062cf5a 100644 --- a/vignettes/gallery_figs/gallery_03.R +++ b/vignettes/gallery_figs/points-by-facet-iris.R @@ -4,7 +4,5 @@ tinyplot( Sepal.Length ~ Petal.Length | Sepal.Length, data = iris, facet = ~Species, - pch = 19, - main = "Faceted flowers", - sub = "Brought to you by tinyplot" + pch = 19 ) diff --git a/vignettes/gallery_figs/gallery_01.R b/vignettes/gallery_figs/points-by-iris.R similarity index 100% rename from vignettes/gallery_figs/gallery_01.R rename to vignettes/gallery_figs/points-by-iris.R diff --git a/vignettes/gallery_figs/gallery_12.R b/vignettes/gallery_figs/polygons.R similarity index 54% rename from vignettes/gallery_figs/gallery_12.R rename to vignettes/gallery_figs/polygons.R index f9319383..b520e7b8 100644 --- a/vignettes/gallery_figs/gallery_12.R +++ b/vignettes/gallery_figs/polygons.R @@ -1,6 +1,7 @@ library("tinyplot") -tinyplot( +plt( x = 1:9, y = c(2,1,2,1,NA,2,1,2,1), - type = type_polygon(density = c(10, 20))) + type = type_polygon(density = c(10, 20)) +) diff --git a/vignettes/gallery_figs/gallery_07.R b/vignettes/gallery_figs/rect-by.R similarity index 64% rename from vignettes/gallery_figs/gallery_07.R rename to vignettes/gallery_figs/rect-by.R index 8595ca3b..810251a5 100644 --- a/vignettes/gallery_figs/gallery_07.R +++ b/vignettes/gallery_figs/rect-by.R @@ -1,5 +1,4 @@ library("tinyplot") -tinytheme("clean") i = 4*(0:10) @@ -7,7 +6,5 @@ tinyplot( xmin = 100+i, ymin = 300+i, xmax = 150+i, ymax = 380+i, by = i, fill = 0.2, type = "rect", - palette = "viridis" + theme = "clean" ) - -tinytheme() # reset theme (optional) \ No newline at end of file diff --git a/vignettes/gallery_figs/gallery_08.R b/vignettes/gallery_figs/ridge-aq.R similarity index 80% rename from vignettes/gallery_figs/gallery_08.R rename to vignettes/gallery_figs/ridge-aq.R index 3b15f330..f060e2f2 100644 --- a/vignettes/gallery_figs/gallery_08.R +++ b/vignettes/gallery_figs/ridge-aq.R @@ -10,7 +10,6 @@ aq = transform( tinyplot(Month ~ Temp | Temp, data = aq, - type = type_ridge(col = "white") + type = type_ridge(col = "white"), + theme = "ridge2" ) - -tinytheme() # reset theme (optional) \ No newline at end of file diff --git a/vignettes/gallery_figs/gallery_04.R b/vignettes/gallery_figs/spineplot-titanic.R similarity index 100% rename from vignettes/gallery_figs/gallery_04.R rename to vignettes/gallery_figs/spineplot-titanic.R