diff --git a/NEWS.md b/NEWS.md index d4a8598..7b3f467 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ * updated citation * added warning when specified size is more than 1000 times smaller than the y-axis range (mostly useful for when making maps with coord_sf) (#86) +* changed the defaults and behavior of the color and fill argument/aesthetics to better maintain backwards compatibility but also prevent unnecessary outlines (#87) # rphylopic 1.2.2 diff --git a/R/add_phylopic.r b/R/add_phylopic.r index 8dbf5c8..42a593d 100644 --- a/R/add_phylopic.r +++ b/R/add_phylopic.r @@ -21,11 +21,13 @@ #' of the silhouette (0 is fully transparent, 1 is fully opaque). #' @param color \code{character}. Color of silhouette outline. If "original" or #' NA is specified, the original color of the silhouette outline will be used -#' (usually the same as "transparent"). +#' (usually the same as "transparent"). To remove the outline, you can set +#' this to "transparent". #' @param fill \code{character}. Color of silhouette. If "original" is #' specified, the original color of the silhouette will be used (usually the -#' same as "black"). If `color` is specified and `fill` is NA the outline and -#' fill color will be the same. +#' same as "black"). If `color` is specified and `fill` is NA, `color` will be +#' used as the fill color (for backwards compatibility). To remove the fill, +#' you can set this to "transparent". #' @param horizontal \code{logical}. Should the silhouette be flipped #' horizontally? #' @param vertical \code{logical}. Should the silhouette be flipped vertically? @@ -68,7 +70,7 @@ #' angle <- runif(10, 0, 360) #' hor <- sample(c(TRUE, FALSE), 10, TRUE) #' ver <- sample(c(TRUE, FALSE), 10, TRUE) -#' cols <- sample(c("black", "darkorange", "grey42", "white"), 10, +#' fills <- sample(c("black", "darkorange", "grey42", "white"), 10, #' replace = TRUE) #' alpha <- runif(10, 0.3, 1) #' @@ -76,12 +78,12 @@ #' geom_blank() + #' add_phylopic(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", #' x = posx, y = posy, ysize = sizey, -#' color = cols, alpha = alpha, angle = angle, +#' fill = fills, alpha = alpha, angle = angle, #' horizontal = hor, vertical = ver) #' p + ggtitle("R Cat Herd!!") add_phylopic <- function(img = NULL, name = NULL, uuid = NULL, filter = NULL, x, y, ysize = Inf, - alpha = 1, color = "black", fill = NA, + alpha = 1, color = NA, fill = "black", horizontal = FALSE, vertical = FALSE, angle = 0, remove_background = TRUE, verbose = FALSE) { if (all(sapply(list(img, name, uuid), is.null))) { diff --git a/R/add_phylopic_base.r b/R/add_phylopic_base.r index 5acf4ff..64fbc58 100644 --- a/R/add_phylopic_base.r +++ b/R/add_phylopic_base.r @@ -23,11 +23,13 @@ #' of the silhouette (0 is fully transparent, 1 is fully opaque). #' @param color \code{character}. Color of silhouette outline. If "original" or #' NA is specified, the original color of the silhouette outline will be used -#' (usually the same as "transparent"). +#' (usually the same as "transparent"). To remove the outline, you can set +#' this to "transparent". #' @param fill \code{character}. Color of silhouette. If "original" is #' specified, the original color of the silhouette will be used (usually the -#' same as "black"). If `color` is specified and `fill` is NA the outline and -#' fill color will be the same. +#' same as "black"). If `color` is specified and `fill` is NA, `color` will be +#' used as the fill color (for backwards compatibility). To remove the fill, +#' you can set this to "transparent". #' @param horizontal \code{logical}. Should the silhouette be flipped #' horizontally? #' @param vertical \code{logical}. Should the silhouette be flipped vertically? @@ -75,13 +77,13 @@ #' angle <- runif(10, 0, 360) #' hor <- sample(c(TRUE, FALSE), 10, TRUE) #' ver <- sample(c(TRUE, FALSE), 10, TRUE) -#' cols <- sample(c("black", "darkorange", "grey42", "white"), 10, +#' fills <- sample(c("black", "darkorange", "grey42", "white"), 10, #' replace = TRUE) #' #' plot(posx, posy, type = "n", main = "A cat herd") #' add_phylopic_base(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", #' x = posx, y = posy, ysize = size, -#' color = cols, angle = angle, +#' fill = fills, angle = angle, #' horizontal = hor, vertical = ver) #' #' # Example using a cat background @@ -96,7 +98,7 @@ add_phylopic_base <- function(img = NULL, name = NULL, uuid = NULL, filter = NULL, x = NULL, y = NULL, ysize = NULL, - alpha = 1, color = "black", fill = NA, + alpha = 1, color = NA, fill = "black", horizontal = FALSE, vertical = FALSE, angle = 0, remove_background = TRUE, verbose = FALSE) { if (all(sapply(list(img, name, uuid), is.null))) { @@ -190,9 +192,12 @@ add_phylopic_base <- function(img = NULL, name = NULL, uuid = NULL, if (angle != 0) img <- rotate_phylopic(img, angle) # recolor if necessary - color <- if (is.na(color) || color == "original") NULL else color - if (is.na(fill)) fill <- color - fill <- if (fill == "original") NULL else fill + if (is.na(color) || color == "original") color <- NULL + if (is.na(fill)) { + fill <- color + color <- NULL + } + if (fill == "original") fill <- NULL img <- recolor_phylopic(img, alpha, color, fill, remove_background) # grobify and plot diff --git a/R/geom_phylopic.R b/R/geom_phylopic.R index 5615548..cbfaeae 100644 --- a/R/geom_phylopic.R +++ b/R/geom_phylopic.R @@ -14,15 +14,16 @@ phylopic_env <- new.env() #' specifies the height of the silhouettes in the units of the y axis. The #' aspect ratio of the silhouettes will always be maintained. #' -#' The `color` (default: "black"), `fill` (default: NA), and `alpha` (default: -#' 1) aesthetics can be used to change the outline color, fill color, and -#' transparency (outline and fill) of the silhouettes, respectively. If -#' `color` is specified and `fill` is NA the outline and fill color will be -#' the same. If "original" is specified for the `color` aesthetic, the -#' original color of the silhouette outline will be used (usually the same as -#' "transparent"). If "original" is specified for the `fill` aesthetic, the -#' original color of the silhouette body will be used (usually the same as -#' "black"). +#' The `color` (default: NA), `fill` (default: "black"), and `alpha` ( +#' default: 1) aesthetics can be used to change the outline color, fill color, +#' and transparency (outline and fill) of the silhouettes, respectively. If +#' `color` is specified and `fill` is NA `color` will be used as the fill +#' color (for backwards compatibility). If "original" is specified for the +#' `color` aesthetic, the original color of the silhouette outline will be +#' used (usually the same as "transparent"). If "original" is specified for +#' the `fill` aesthetic, the original color of the silhouette body will be +#' used (usually the same as "black"). To remove the fill or outline, you can +#' set `fill` or `color` to "transparent", respectively. #' #' The `horizontal` and `vertical` aesthetics can be used to flip the #' silhouettes. The `angle` aesthetic can be used to rotate the silhouettes. @@ -74,7 +75,7 @@ phylopic_env <- new.env() #' name = c("Felis silvestris catus", "Odobenus rosmarus")) #' ggplot(df) + #' geom_phylopic(aes(x = x, y = y, name = name), -#' color = "purple", size = 10) + +#' fill = "purple", size = 10) + #' facet_wrap(~name) + #' coord_cartesian(xlim = c(1,6), ylim = c(5, 30)) #' } @@ -120,11 +121,10 @@ geom_phylopic <- function(mapping = NULL, data = NULL, #' @importFrom grid gTree gList nullGrob GeomPhylopic <- ggproto("GeomPhylopic", Geom, required_aes = c("x", "y"), - non_missing_aes = c("size", "alpha", "color", + non_missing_aes = c("size", "alpha", "color", "fill", "horizontal", "vertical", "angle"), optional_aes = c("img", "name", "uuid"), # one and only one of these - default_aes = aes(size = 6, alpha = 1, - color = "black", fill = NA, + default_aes = aes(size = 6, alpha = 1, color = NA, fill = "black", horizontal = FALSE, vertical = FALSE, angle = 0), extra_params = c("na.rm", "remove_background", "verbose", "filter"), setup_data = function(data, params) { @@ -212,6 +212,7 @@ GeomPhylopic <- ggproto("GeomPhylopic", Geom, data <- ggproto_parent(Geom, self)$use_defaults(data, params, modifiers) if (col_fill[1] && !col_fill[2]) { data$fill <- data$colour + data$colour <- NA } data }, diff --git a/man/add_phylopic.Rd b/man/add_phylopic.Rd index 6d30d32..ee18b0a 100644 --- a/man/add_phylopic.Rd +++ b/man/add_phylopic.Rd @@ -13,8 +13,8 @@ add_phylopic( y, ysize = Inf, alpha = 1, - color = "black", - fill = NA, + color = NA, + fill = "black", horizontal = FALSE, vertical = FALSE, angle = 0, @@ -49,12 +49,14 @@ of the silhouette (0 is fully transparent, 1 is fully opaque).} \item{color}{\code{character}. Color of silhouette outline. If "original" or NA is specified, the original color of the silhouette outline will be used -(usually the same as "transparent").} +(usually the same as "transparent"). To remove the outline, you can set +this to "transparent".} \item{fill}{\code{character}. Color of silhouette. If "original" is specified, the original color of the silhouette will be used (usually the -same as "black"). If \code{color} is specified and \code{fill} is NA the outline and -fill color will be the same.} +same as "black"). If \code{color} is specified and \code{fill} is NA, \code{color} will be +used as the fill color (for backwards compatibility). To remove the fill, +you can set this to "transparent".} \item{horizontal}{\code{logical}. Should the silhouette be flipped horizontally?} @@ -107,7 +109,7 @@ sizey <- runif(10, 0.4, 2) angle <- runif(10, 0, 360) hor <- sample(c(TRUE, FALSE), 10, TRUE) ver <- sample(c(TRUE, FALSE), 10, TRUE) -cols <- sample(c("black", "darkorange", "grey42", "white"), 10, +fills <- sample(c("black", "darkorange", "grey42", "white"), 10, replace = TRUE) alpha <- runif(10, 0.3, 1) @@ -115,7 +117,7 @@ p <- ggplot(data.frame(cat.x = posx, cat.y = posy), aes(cat.x, cat.y)) + geom_blank() + add_phylopic(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = posx, y = posy, ysize = sizey, - color = cols, alpha = alpha, angle = angle, + fill = fills, alpha = alpha, angle = angle, horizontal = hor, vertical = ver) p + ggtitle("R Cat Herd!!") } diff --git a/man/add_phylopic_base.Rd b/man/add_phylopic_base.Rd index 7c9b2d9..197ba36 100644 --- a/man/add_phylopic_base.Rd +++ b/man/add_phylopic_base.Rd @@ -13,8 +13,8 @@ add_phylopic_base( y = NULL, ysize = NULL, alpha = 1, - color = "black", - fill = NA, + color = NA, + fill = "black", horizontal = FALSE, vertical = FALSE, angle = 0, @@ -51,12 +51,14 @@ of the silhouette (0 is fully transparent, 1 is fully opaque).} \item{color}{\code{character}. Color of silhouette outline. If "original" or NA is specified, the original color of the silhouette outline will be used -(usually the same as "transparent").} +(usually the same as "transparent"). To remove the outline, you can set +this to "transparent".} \item{fill}{\code{character}. Color of silhouette. If "original" is specified, the original color of the silhouette will be used (usually the -same as "black"). If \code{color} is specified and \code{fill} is NA the outline and -fill color will be the same.} +same as "black"). If \code{color} is specified and \code{fill} is NA, \code{color} will be +used as the fill color (for backwards compatibility). To remove the fill, +you can set this to "transparent".} \item{horizontal}{\code{logical}. Should the silhouette be flipped horizontally?} @@ -111,13 +113,13 @@ size <- runif(10, 0.1, 0.3) angle <- runif(10, 0, 360) hor <- sample(c(TRUE, FALSE), 10, TRUE) ver <- sample(c(TRUE, FALSE), 10, TRUE) -cols <- sample(c("black", "darkorange", "grey42", "white"), 10, +fills <- sample(c("black", "darkorange", "grey42", "white"), 10, replace = TRUE) plot(posx, posy, type = "n", main = "A cat herd") add_phylopic_base(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = posx, y = posy, ysize = size, - color = cols, angle = angle, + fill = fills, angle = angle, horizontal = hor, vertical = ver) # Example using a cat background diff --git a/man/geom_phylopic.Rd b/man/geom_phylopic.Rd index 5307862..78e0887 100644 --- a/man/geom_phylopic.Rd +++ b/man/geom_phylopic.Rd @@ -76,8 +76,8 @@ used silhouette(s) be printed to the console (see \code{\link[=get_attribution]{ \item{filter}{\code{character}. Filter by usage license if using the \code{name} aesthetic. Use "by" to limit results to images which do not require attribution, "nc" for images which allows commercial usage, and "sa" for -images without a ShareAlike clause. The user can also combine these -filters as a vector.} +images without a ShareAlike clause. The user can also combine these filters +as a vector.} } \description{ This geom acts like \code{\link[ggplot2:geom_point]{ggplot2::geom_point()}}, except that the specified @@ -93,17 +93,16 @@ silhouettes at specified positions on the plot. The \code{size} aesthetic specifies the height of the silhouettes in the units of the y axis. The aspect ratio of the silhouettes will always be maintained. -The \code{color} (default: "black"), \code{fill} (default: NA), and \code{alpha} (default: -\enumerate{ -\item aesthetics can be used to change the outline color, fill color, and -transparency (outline and fill) of the silhouettes, respectively. If -\code{color} is specified and \code{fill} is NA the outline and fill color will be -the same. If "original" is specified for the \code{color} aesthetic, the -original color of the silhouette outline will be used (usually the same as -"transparent"). If "original" is specified for the \code{fill} aesthetic, the -original color of the silhouette body will be used (usually the same as -"black"). -} +The \code{color} (default: NA), \code{fill} (default: "black"), and \code{alpha} ( +default: 1) aesthetics can be used to change the outline color, fill color, +and transparency (outline and fill) of the silhouettes, respectively. If +\code{color} is specified and \code{fill} is NA \code{color} will be used as the fill +color (for backwards compatibility). If "original" is specified for the +\code{color} aesthetic, the original color of the silhouette outline will be +used (usually the same as "transparent"). If "original" is specified for +the \code{fill} aesthetic, the original color of the silhouette body will be +used (usually the same as "black"). To remove the fill or outline, you can +set \code{fill} or \code{color} to "transparent", respectively. The \code{horizontal} and \code{vertical} aesthetics can be used to flip the silhouettes. The \code{angle} aesthetic can be used to rotate the silhouettes. @@ -140,7 +139,7 @@ df <- data.frame(x = c(2, 4), y = c(10, 20), name = c("Felis silvestris catus", "Odobenus rosmarus")) ggplot(df) + geom_phylopic(aes(x = x, y = y, name = name), - color = "purple", size = 10) + + fill = "purple", size = 10) + facet_wrap(~name) + coord_cartesian(xlim = c(1,6), ylim = c(5, 30)) } diff --git a/tests/testthat/_snaps/add_phylopic/phylopic-in-background.svg b/tests/testthat/_snaps/add_phylopic/phylopic-in-background.svg index ca25f80..53e6d1e 100644 --- a/tests/testthat/_snaps/add_phylopic/phylopic-in-background.svg +++ b/tests/testthat/_snaps/add_phylopic/phylopic-in-background.svg @@ -35,21 +35,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/tests/testthat/_snaps/add_phylopic/phylopics-on-top-of-plot.svg b/tests/testthat/_snaps/add_phylopic/phylopics-on-top-of-plot.svg index b254264..eb217a2 100644 --- a/tests/testthat/_snaps/add_phylopic/phylopics-on-top-of-plot.svg +++ b/tests/testthat/_snaps/add_phylopic/phylopics-on-top-of-plot.svg @@ -35,7 +35,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -57,7 +57,7 @@ - + @@ -68,7 +68,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -90,7 +90,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -112,7 +112,7 @@ - + @@ -134,7 +134,7 @@ - + @@ -156,7 +156,7 @@ - + @@ -167,7 +167,7 @@ - + @@ -189,7 +189,7 @@ - + @@ -200,7 +200,7 @@ - + @@ -211,7 +211,7 @@ - + @@ -222,7 +222,7 @@ - + @@ -233,7 +233,7 @@ - + @@ -244,7 +244,7 @@ - + @@ -255,7 +255,7 @@ - + @@ -277,7 +277,7 @@ - + @@ -321,7 +321,7 @@ - + @@ -354,7 +354,7 @@ - + @@ -365,7 +365,7 @@ - + @@ -398,7 +398,7 @@ - + @@ -409,7 +409,7 @@ - + @@ -420,7 +420,7 @@ - + @@ -431,7 +431,7 @@ - + @@ -442,7 +442,7 @@ - + @@ -453,7 +453,7 @@ - + @@ -464,7 +464,7 @@ - + @@ -475,7 +475,7 @@ - + @@ -497,7 +497,7 @@ - + @@ -508,7 +508,7 @@ - + @@ -519,7 +519,7 @@ - + @@ -530,7 +530,7 @@ - + @@ -541,7 +541,7 @@ - + @@ -552,7 +552,7 @@ - + @@ -563,7 +563,7 @@ - + @@ -574,7 +574,7 @@ - + diff --git a/tests/testthat/_snaps/add_phylopic_base/phylopic-in-background.svg b/tests/testthat/_snaps/add_phylopic_base/phylopic-in-background.svg index f6b9bbf..1249d99 100644 --- a/tests/testthat/_snaps/add_phylopic_base/phylopic-in-background.svg +++ b/tests/testthat/_snaps/add_phylopic_base/phylopic-in-background.svg @@ -52,8 +52,8 @@ - - + + diff --git a/tests/testthat/_snaps/add_phylopic_base/phylopics-on-top-of-plot.svg b/tests/testthat/_snaps/add_phylopic_base/phylopics-on-top-of-plot.svg index 91e0d57..4e53e39 100644 --- a/tests/testthat/_snaps/add_phylopic_base/phylopics-on-top-of-plot.svg +++ b/tests/testthat/_snaps/add_phylopic_base/phylopics-on-top-of-plot.svg @@ -54,7 +54,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -76,7 +76,7 @@ - + @@ -87,7 +87,7 @@ - + @@ -98,7 +98,7 @@ - + @@ -109,7 +109,7 @@ - + @@ -120,7 +120,7 @@ - + @@ -131,7 +131,7 @@ - + @@ -142,7 +142,7 @@ - + @@ -153,7 +153,7 @@ - + @@ -175,7 +175,7 @@ - + @@ -186,7 +186,7 @@ - + @@ -197,7 +197,7 @@ - + @@ -208,7 +208,7 @@ - + @@ -219,7 +219,7 @@ - + @@ -230,7 +230,7 @@ - + @@ -241,7 +241,7 @@ - + @@ -252,7 +252,7 @@ - + @@ -263,7 +263,7 @@ - + @@ -274,7 +274,7 @@ - + @@ -285,7 +285,7 @@ - + @@ -296,7 +296,7 @@ - + @@ -307,7 +307,7 @@ - + @@ -318,7 +318,7 @@ - + @@ -329,7 +329,7 @@ - + @@ -340,7 +340,7 @@ - + @@ -351,7 +351,7 @@ - + @@ -362,7 +362,7 @@ - + @@ -373,7 +373,7 @@ - + @@ -384,7 +384,7 @@ - + @@ -395,7 +395,7 @@ - + @@ -417,7 +417,7 @@ - + @@ -428,7 +428,7 @@ - + @@ -439,7 +439,7 @@ - + @@ -450,7 +450,7 @@ - + @@ -461,7 +461,7 @@ - + @@ -472,7 +472,7 @@ - + @@ -483,7 +483,7 @@ - + @@ -494,7 +494,7 @@ - + @@ -505,7 +505,7 @@ - + @@ -516,7 +516,7 @@ - + @@ -527,7 +527,7 @@ - + @@ -538,7 +538,7 @@ - + @@ -549,7 +549,7 @@ - + @@ -560,7 +560,7 @@ - + @@ -571,7 +571,7 @@ - + @@ -582,7 +582,7 @@ - + @@ -593,7 +593,7 @@ - + diff --git a/tests/testthat/_snaps/geom_phylopic/geom-phylopic.svg b/tests/testthat/_snaps/geom_phylopic/geom-phylopic.svg index 2ca6098..f7a30b8 100644 --- a/tests/testthat/_snaps/geom_phylopic/geom-phylopic.svg +++ b/tests/testthat/_snaps/geom_phylopic/geom-phylopic.svg @@ -35,21 +35,21 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -70,7 +70,7 @@ - + @@ -91,8 +91,8 @@ - - + + @@ -113,8 +113,8 @@ - - + + diff --git a/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-img.svg b/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-img.svg index 9f9ff18..b6eda00 100644 --- a/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-img.svg +++ b/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-img.svg @@ -35,8 +35,8 @@ - - + + @@ -47,7 +47,7 @@ - + @@ -78,7 +78,7 @@ - + @@ -89,7 +89,7 @@ - + Felis silvestris catus diff --git a/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-larger-glyphs.svg b/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-larger-glyphs.svg index 425114e..4d18fba 100644 --- a/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-larger-glyphs.svg +++ b/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-larger-glyphs.svg @@ -35,8 +35,8 @@ - - + + @@ -47,7 +47,7 @@ - + @@ -78,8 +78,8 @@ - - + + @@ -90,7 +90,7 @@ - + Felis silvestris catus diff --git a/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-uuid.svg b/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-uuid.svg index 67cc415..e6602d4 100644 --- a/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-uuid.svg +++ b/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph-with-uuid.svg @@ -35,8 +35,8 @@ - - + + @@ -47,7 +47,7 @@ - + @@ -78,18 +78,18 @@ - + - - + + - - - + + + Felis silvestris catus diff --git a/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph.svg b/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph.svg index 8c97b00..3a341f9 100644 --- a/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph.svg +++ b/tests/testthat/_snaps/geom_phylopic/phylopic-key-glyph.svg @@ -35,8 +35,8 @@ - - + + @@ -47,7 +47,7 @@ - + @@ -78,8 +78,8 @@ - - + + @@ -90,7 +90,7 @@ - + Felis silvestris catus diff --git a/tests/testthat/test-add_phylopic.R b/tests/testthat/test-add_phylopic.R index 447567d..79da2c6 100644 --- a/tests/testthat/test-add_phylopic.R +++ b/tests/testthat/test-add_phylopic.R @@ -27,15 +27,16 @@ test_that("add_phylopic works", { angle <- runif(50, 0, 360) hor <- sample(c(TRUE, FALSE), 50, TRUE) ver <- sample(c(TRUE, FALSE), 50, TRUE) - cols <- sample(c("black", "darkorange", "grey42", "white"), 50, + fills <- sample(c("black", "darkorange", "grey42", "white"), 50, replace = TRUE) + cols <- ifelse(fills == "white", "black", NA) alpha <- runif(50, 0, 1) p <- ggplot(data.frame(cat.x = posx, cat.y = posy), aes(cat.x, cat.y)) + geom_blank() + add_phylopic(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = posx, y = posy, ysize = sizey, - fill = cols, alpha = alpha, + fill = fills, color = cols, alpha = alpha, angle = angle, horizontal = hor, vertical = ver) p <- p + ggtitle("R Cat Herd!!") expect_doppelganger("phylopics on top of plot", p) diff --git a/tests/testthat/test-add_phylopic_base.R b/tests/testthat/test-add_phylopic_base.R index 843063b..a5d47a0 100644 --- a/tests/testthat/test-add_phylopic_base.R +++ b/tests/testthat/test-add_phylopic_base.R @@ -25,15 +25,16 @@ test_that("add_phylopic_base works", { angle <- runif(50, 0, 360) hor <- sample(c(TRUE, FALSE), 50, TRUE) ver <- sample(c(TRUE, FALSE), 50, TRUE) - cols <- sample(c("black", "darkorange", "grey42", "white"), 50, - replace = TRUE) + fills <- sample(c("black", "darkorange", "grey42", "white"), 50, + replace = TRUE) + cols <- ifelse(fills == "white", "black", NA) alpha <- runif(50, 0, 1) expect_doppelganger("phylopics on top of plot", function() { plot(posx, posy, type = "n", main = "A cat herd") add_phylopic_base(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = posx, y = posy, ysize = sizey, - color = cols, alpha = alpha, + fill = fills, color = cols, alpha = alpha, angle = angle, horizontal = hor, vertical = ver) }) diff --git a/tests/testthat/test-geom_phylopic.R b/tests/testthat/test-geom_phylopic.R index 6b12966..152794d 100644 --- a/tests/testthat/test-geom_phylopic.R +++ b/tests/testthat/test-geom_phylopic.R @@ -81,7 +81,8 @@ test_that("phylopic_key_glyph works", { aes(x = x, y = y, name = name, color = name), size = 10, show.legend = TRUE, verbose = TRUE, key_glyph = - phylopic_key_glyph(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9") + phylopic_key_glyph(uuid = c("23cd6aa4-9587-4a2e-8e26-de42885004c9", + "16cfde1b-d577-4de8-82b9-62b760aacba5")) ) + coord_cartesian(xlim = c(1, 6), ylim = c(5, 30)) + theme_classic(base_size = 16) @@ -102,8 +103,10 @@ test_that("phylopic_key_glyph works", { aes(x = x, y = y, name = name, color = name), size = 10, show.legend = TRUE, verbose = TRUE, key_glyph = - phylopic_key_glyph(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", - img = cat) + phylopic_key_glyph( + uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", + img = cat + ) ) + coord_cartesian(xlim = c(1, 6), ylim = c(5, 30)) + theme_classic(base_size = 16)) diff --git a/vignettes/a-getting-started.Rmd b/vignettes/a-getting-started.Rmd index 856f18e..214b272 100644 --- a/vignettes/a-getting-started.Rmd +++ b/vignettes/a-getting-started.Rmd @@ -9,7 +9,7 @@ vignette: > **Authors:** Lewis A. Jones & William Gearty -**Last updated:** 2023-11-09 +**Last updated:** 2023-11-16 @@ -171,13 +171,12 @@ The `rotate_phylopic()` function can be used to rotate a silhouette an arbitrary img_rot <- rotate_phylopic(img = img, angle = 45) ``` -Finally, the `recolor_phylopic()` function can be used to modify the color and/or transparency of a silhouette. The vast majority of PhyloPic silhouettes are black and fully opaque by default. However, it may be useful to change this when the you are trying to either match an existing visualization color palette or trying to convey extra information, such as categorical data, through color. +Finally, the `recolor_phylopic()` function can be used to modify the fill color, outline color, and/or transparency of a silhouette. The vast majority of PhyloPic silhouettes are solid black, are fully opaque, and have a transparent outline by default. However, it may be useful to change this when the you are trying to either match an existing visualization color palette or trying to convey extra information, such as categorical data, through color. ```r -# Change color to blue and transparency to 50% -img_col <- recolor_phylopic(img = img, alpha = 0.5, - color = "blue", fill = "blue") +# Change fill color to blue and transparency to 50% +img_col <- recolor_phylopic(img = img, alpha = 0.5, fill = "blue") ``` Let's see what those look like in the same plot: @@ -189,7 +188,7 @@ ggplot() + add_phylopic(img = img_flip, x = 1.25, y = 1.25, ysize = 0.25) + add_phylopic(img = img_rot, x = 1, y = 1, ysize = 0.25) + add_phylopic(img = img_col, x = 0.75, y = 0.75, ysize = 0.25, - color = "original") + fill = "original") ```
@@ -199,7 +198,7 @@ ggplot() + You'll notice that the rotated silhouette is smaller than the other two silhouettes. This is because our functions have arguments to specify the height (`ysize`). The width is automatically set to maintain the original aspect ratio of the silhouette. In this case, the aspect ratio of the rotated silhouette has changed, so the same height results in a smaller silhouette overall. -For convenience, we have also included these transformation options within all of the visualization functions. The default color is "black", hence why we needed to specify `color = "original"` above. However, when the same transformed silhouette will be used for multiple visualizations, we suggest transforming the silhouette first, saving it as a new object, then using this new object for visualization purposes. +For convenience, we have also included these transformation options within all of the visualization functions. The default fill is "black", hence why we needed to specify `fill = "original"` above. However, when the same transformed silhouette will be used for multiple visualizations, we suggest transforming the silhouette first, saving it as a new object, then using this new object for visualization purposes. ## Get attribution Now that you've made a plot and used some silhouettes, you should acknowledge the contributors that made those silhouettes. Fortunately, **rphylopic** includes the `get_attribution()` function to get contributor data about specific images: diff --git a/vignettes/a-getting-started.Rmd.orig b/vignettes/a-getting-started.Rmd.orig index 20f54ae..f715f3c 100644 --- a/vignettes/a-getting-started.Rmd.orig +++ b/vignettes/a-getting-started.Rmd.orig @@ -135,12 +135,11 @@ The `rotate_phylopic()` function can be used to rotate a silhouette an arbitrary img_rot <- rotate_phylopic(img = img, angle = 45) ``` -Finally, the `recolor_phylopic()` function can be used to modify the color and/or transparency of a silhouette. The vast majority of PhyloPic silhouettes are black and fully opaque by default. However, it may be useful to change this when the you are trying to either match an existing visualization color palette or trying to convey extra information, such as categorical data, through color. +Finally, the `recolor_phylopic()` function can be used to modify the fill color, outline color, and/or transparency of a silhouette. The vast majority of PhyloPic silhouettes are solid black, are fully opaque, and have a transparent outline by default. However, it may be useful to change this when the you are trying to either match an existing visualization color palette or trying to convey extra information, such as categorical data, through color. ```{r} -# Change color to blue and transparency to 50% -img_col <- recolor_phylopic(img = img, alpha = 0.5, - color = "blue", fill = "blue") +# Change fill color to blue and transparency to 50% +img_col <- recolor_phylopic(img = img, alpha = 0.5, fill = "blue") ``` Let's see what those look like in the same plot: @@ -151,12 +150,12 @@ ggplot() + add_phylopic(img = img_flip, x = 1.25, y = 1.25, ysize = 0.25) + add_phylopic(img = img_rot, x = 1, y = 1, ysize = 0.25) + add_phylopic(img = img_col, x = 0.75, y = 0.75, ysize = 0.25, - color = "original") + fill = "original") ``` You'll notice that the rotated silhouette is smaller than the other two silhouettes. This is because our functions have arguments to specify the height (`ysize`). The width is automatically set to maintain the original aspect ratio of the silhouette. In this case, the aspect ratio of the rotated silhouette has changed, so the same height results in a smaller silhouette overall. -For convenience, we have also included these transformation options within all of the visualization functions. The default color is "black", hence why we needed to specify `color = "original"` above. However, when the same transformed silhouette will be used for multiple visualizations, we suggest transforming the silhouette first, saving it as a new object, then using this new object for visualization purposes. +For convenience, we have also included these transformation options within all of the visualization functions. The default fill is "black", hence why we needed to specify `fill = "original"` above. However, when the same transformed silhouette will be used for multiple visualizations, we suggest transforming the silhouette first, saving it as a new object, then using this new object for visualization purposes. ## Get attribution Now that you've made a plot and used some silhouettes, you should acknowledge the contributors that made those silhouettes. Fortunately, **rphylopic** includes the `get_attribution()` function to get contributor data about specific images: diff --git a/vignettes/b-advanced-ggplot.Rmd b/vignettes/b-advanced-ggplot.Rmd index ff4bc3f..e04cb2c 100644 --- a/vignettes/b-advanced-ggplot.Rmd +++ b/vignettes/b-advanced-ggplot.Rmd @@ -9,7 +9,7 @@ vignette: > **Authors:** William Gearty & Lewis A. Jones -**Last updated:** 2023-11-09 +**Last updated:** 2023-11-16 @@ -124,19 +124,20 @@ ggplot(penguins_subset) +

plot of chunk ggplot-penguin-plot-4

-Finally, let's color the female and male penguins with different colors. Note that the default for `geom_phylopic()` is to not display a legend, so we need to set `show.legend = TRUE`. However, we only want a legend for the colors, so we use `guide = "none"` for the size scale: +Finally, let's give the female and male penguins different fill colors. Note that the default for `geom_phylopic()` is to not display a legend, so we need to set `show.legend = TRUE`. However, we only want a legend for the fill colors, so we use `guide = "none"` for the size scale. We also want to show the fill color in the legend, so we need to override the shape: ```r ggplot(penguins_subset) + geom_phylopic(img = penguin_rot, aes(x = bill_length_mm, y = flipper_length_mm, - size = body_mass_g, color = sex), + size = body_mass_g, fill = sex), show.legend = TRUE) + labs(x = "Bill length (mm)", y = "Flipper length (mm)") + scale_size_continuous(guide = "none") + - scale_color_manual("Sex", values = c("orange", "blue"), - labels = c("Female", "Male")) + + scale_fill_manual("Sex", values = c("orange", "blue"), + labels = c("Female", "Male"), + guide = guide_legend(override.aes = list(shape = 21))) + facet_wrap(~species, ncol = 1) + theme_bw(base_size = 15) + theme(legend.position = c(0.9, 0.9)) @@ -154,12 +155,12 @@ Hmm...the colored dots in the legend are great, but lucky for us, the package al ggplot(penguins_subset) + geom_phylopic(img = penguin_rot, aes(x = bill_length_mm, y = flipper_length_mm, - size = body_mass_g, color = sex), + size = body_mass_g, fill = sex), show.legend = TRUE, key_glyph = phylopic_key_glyph(img = penguin_rot)) + labs(x = "Bill length (mm)", y = "Flipper length (mm)") + scale_size_continuous(guide = "none") + - scale_color_manual("Sex", values = c("orange", "blue"), + scale_fill_manual("Sex", values = c("orange", "blue"), labels = c("Female", "Male")) + facet_wrap(~species, ncol = 1) + theme_bw(base_size = 15) + @@ -198,7 +199,7 @@ Then we'll subset our occurrences to only those for *Diplocaulus*: tetrapods <- subset(tetrapods, genus == "Diplocaulus") ``` -Now, let's plot those occurrences on a world map. `{ggplot2}` and it's built-in function `map_data()` make this a breeze. Note that we use `alpha = 0.75` in case there are multiple occurrences in the same place. That way, the darker the color, the more occurrences in that geographic location. +Now, let's plot those occurrences on a world map. `{ggplot2}` and it's built-in function `map_data()` make this a breeze. Note that we use `alpha = 0.75` in case there are multiple occurrences in the same place. That way, the darker the fill color, the more occurrences in that geographic location. ```r @@ -209,7 +210,7 @@ world <- st_wrap_dateline(world) ggplot(world) + geom_sf(fill = "lightgray", color = "darkgrey", linewidth = 0.1) + geom_point(data = tetrapods, aes(x = lng, y = lat), - size = 4, alpha = 0.75, color = "blue") + + size = 4, alpha = 0.75, fill = "blue") + theme_void() + coord_sf() ``` @@ -226,7 +227,7 @@ Now, as with the penguin figure above, we can easily replace those points with s ggplot(world) + geom_sf(fill = "lightgray", color = "darkgrey", linewidth = 0.1) + geom_phylopic(data = tetrapods, aes(x = lng, y = lat, name = genus), - size = 4, alpha = 0.75, color = "blue") + + size = 4, alpha = 0.75, fill = "blue") + theme_void() + coord_sf() ``` @@ -250,7 +251,7 @@ bbox <- st_graticule(crs = st_crs("ESRI:54030"), ggplot(world) + geom_sf(fill = "lightgray", color = "darkgrey", linewidth = 0.1) + geom_phylopic(data = tetrapods, aes(x = lng, y = lat, name = genus), - size = 4E5, alpha = 0.75, color = "blue") + + size = 4E5, alpha = 0.75, fill = "blue") + geom_sf(data = bbox) + theme_void() + coord_sf(default_crs = st_crs(4326), crs = st_crs("ESRI:54030")) diff --git a/vignettes/b-advanced-ggplot.Rmd.orig b/vignettes/b-advanced-ggplot.Rmd.orig index aee3b95..ef31a81 100644 --- a/vignettes/b-advanced-ggplot.Rmd.orig +++ b/vignettes/b-advanced-ggplot.Rmd.orig @@ -103,18 +103,19 @@ ggplot(penguins_subset) + theme_bw(base_size = 15) ``` -Finally, let's color the female and male penguins with different colors. Note that the default for `geom_phylopic()` is to not display a legend, so we need to set `show.legend = TRUE`. However, we only want a legend for the colors, so we use `guide = "none"` for the size scale: +Finally, let's give the female and male penguins different fill colors. Note that the default for `geom_phylopic()` is to not display a legend, so we need to set `show.legend = TRUE`. However, we only want a legend for the fill colors, so we use `guide = "none"` for the size scale. We also want to show the fill color in the legend, so we need to override the shape: ```{r ggplot-penguin-plot-5} ggplot(penguins_subset) + geom_phylopic(img = penguin_rot, aes(x = bill_length_mm, y = flipper_length_mm, - size = body_mass_g, color = sex), + size = body_mass_g, fill = sex), show.legend = TRUE) + labs(x = "Bill length (mm)", y = "Flipper length (mm)") + scale_size_continuous(guide = "none") + - scale_color_manual("Sex", values = c("orange", "blue"), - labels = c("Female", "Male")) + + scale_fill_manual("Sex", values = c("orange", "blue"), + labels = c("Female", "Male"), + guide = guide_legend(override.aes = list(shape = 21))) + facet_wrap(~species, ncol = 1) + theme_bw(base_size = 15) + theme(legend.position = c(0.9, 0.9)) @@ -126,12 +127,12 @@ Hmm...the colored dots in the legend are great, but lucky for us, the package al ggplot(penguins_subset) + geom_phylopic(img = penguin_rot, aes(x = bill_length_mm, y = flipper_length_mm, - size = body_mass_g, color = sex), + size = body_mass_g, fill = sex), show.legend = TRUE, key_glyph = phylopic_key_glyph(img = penguin_rot)) + labs(x = "Bill length (mm)", y = "Flipper length (mm)") + scale_size_continuous(guide = "none") + - scale_color_manual("Sex", values = c("orange", "blue"), + scale_fill_manual("Sex", values = c("orange", "blue"), labels = c("Female", "Male")) + facet_wrap(~species, ncol = 1) + theme_bw(base_size = 15) + @@ -163,7 +164,7 @@ Then we'll subset our occurrences to only those for *Diplocaulus*: tetrapods <- subset(tetrapods, genus == "Diplocaulus") ``` -Now, let's plot those occurrences on a world map. `{ggplot2}` and it's built-in function `map_data()` make this a breeze. Note that we use `alpha = 0.75` in case there are multiple occurrences in the same place. That way, the darker the color, the more occurrences in that geographic location. +Now, let's plot those occurrences on a world map. `{ggplot2}` and it's built-in function `map_data()` make this a breeze. Note that we use `alpha = 0.75` in case there are multiple occurrences in the same place. That way, the darker the fill color, the more occurrences in that geographic location. ```{r ggplot-geog-plot-1, fig.height = 3.5} # Get map data @@ -173,7 +174,7 @@ world <- st_wrap_dateline(world) ggplot(world) + geom_sf(fill = "lightgray", color = "darkgrey", linewidth = 0.1) + geom_point(data = tetrapods, aes(x = lng, y = lat), - size = 4, alpha = 0.75, color = "blue") + + size = 4, alpha = 0.75, fill = "blue") + theme_void() + coord_sf() ``` @@ -184,7 +185,7 @@ Now, as with the penguin figure above, we can easily replace those points with s ggplot(world) + geom_sf(fill = "lightgray", color = "darkgrey", linewidth = 0.1) + geom_phylopic(data = tetrapods, aes(x = lng, y = lat, name = genus), - size = 4, alpha = 0.75, color = "blue") + + size = 4, alpha = 0.75, fill = "blue") + theme_void() + coord_sf() ``` @@ -202,7 +203,7 @@ bbox <- st_graticule(crs = st_crs("ESRI:54030"), ggplot(world) + geom_sf(fill = "lightgray", color = "darkgrey", linewidth = 0.1) + geom_phylopic(data = tetrapods, aes(x = lng, y = lat, name = genus), - size = 4E5, alpha = 0.75, color = "blue") + + size = 4E5, alpha = 0.75, fill = "blue") + geom_sf(data = bbox) + theme_void() + coord_sf(default_crs = st_crs(4326), crs = st_crs("ESRI:54030")) diff --git a/vignettes/base-geog-plot-1-1.png b/vignettes/base-geog-plot-1-1.png index e4d5cab..f3bc3e2 100644 Binary files a/vignettes/base-geog-plot-1-1.png and b/vignettes/base-geog-plot-1-1.png differ diff --git a/vignettes/base-geog-plot-2-1.png b/vignettes/base-geog-plot-2-1.png index 2e9ca68..d40d6ef 100644 Binary files a/vignettes/base-geog-plot-2-1.png and b/vignettes/base-geog-plot-2-1.png differ diff --git a/vignettes/base-penguin-plot-2-1.png b/vignettes/base-penguin-plot-2-1.png index 97ce8a9..035f975 100644 Binary files a/vignettes/base-penguin-plot-2-1.png and b/vignettes/base-penguin-plot-2-1.png differ diff --git a/vignettes/base-penguin-plot-3-1.png b/vignettes/base-penguin-plot-3-1.png index c6e411d..d18dd45 100644 Binary files a/vignettes/base-penguin-plot-3-1.png and b/vignettes/base-penguin-plot-3-1.png differ diff --git a/vignettes/base-penguin-plot-4-1.png b/vignettes/base-penguin-plot-4-1.png index a0da8a2..40ae53d 100644 Binary files a/vignettes/base-penguin-plot-4-1.png and b/vignettes/base-penguin-plot-4-1.png differ diff --git a/vignettes/base-penguin-plot-5-1.png b/vignettes/base-penguin-plot-5-1.png index 1695733..05ee631 100644 Binary files a/vignettes/base-penguin-plot-5-1.png and b/vignettes/base-penguin-plot-5-1.png differ diff --git a/vignettes/base-phylo-plot-3-1.png b/vignettes/base-phylo-plot-3-1.png index a3f2004..a77a4a7 100644 Binary files a/vignettes/base-phylo-plot-3-1.png and b/vignettes/base-phylo-plot-3-1.png differ diff --git a/vignettes/base-phylo-plot-4-1.png b/vignettes/base-phylo-plot-4-1.png index 4faad04..1683911 100644 Binary files a/vignettes/base-phylo-plot-4-1.png and b/vignettes/base-phylo-plot-4-1.png differ diff --git a/vignettes/c-advanced-base.Rmd b/vignettes/c-advanced-base.Rmd index aa2e7c0..4108bdb 100644 --- a/vignettes/c-advanced-base.Rmd +++ b/vignettes/c-advanced-base.Rmd @@ -9,7 +9,7 @@ vignette: > **Authors:** William Gearty & Lewis A. Jones -**Last updated:** 2023-11-09 +**Last updated:** 2023-11-16 @@ -159,7 +159,7 @@ for (i in seq_along(species_split)) {

plot of chunk base-penguin-plot-4

-Finally, let's color the female and male penguins with different colors. We'll also add a legend to the last panel. +Finally, let's give the female and male penguins different fill colors. We'll also add a legend to the last panel. ```r @@ -176,7 +176,7 @@ for (i in seq_along(species_split)) { y = species_data$flipper_length_mm, ysize = species_data$body_mass_g / max(penguins_subset$body_mass_g, na.rm = TRUE) * 8, - color = ifelse(species_data$sex == "male", "blue", "orange")) + fill = ifelse(species_data$sex == "male", "blue", "orange")) } # Add a legend to the last plot @@ -192,7 +192,7 @@ legend("bottomright", legend = c("Female", "Male"), pch = 20, Now that's a nice figure! # Geographic distribution -In much the same way as generic x-y plotting, the **rphylopic** package can be used in base R to plot organism silhouettes on a map. That is, to plot data points (e.g., species occurrences) as silhouettes. We provide an example here of how this might be achieved. For this application, we use the example occurrence dataset of early (Carboniferous to Early Triassic) tetrapods from the `{palaeoverse}` R package to visualize the geographic distribution of *Mesosaurus* fossils. +In much the same way as generic x-y plotting, the **rphylopic** package can be used in base R to plot organism silhouettes on a map. That is, to plot data points (e.g., species occurrences) as silhouettes. We provide an example here of how this might be achieved. For this application, we use the example occurrence dataset of early (Carboniferous to Early Triassic) tetrapods from the `{palaeoverse}` R package to visualize the geographic distribution of *Diplocaulus* fossils. First, let's load our libraries and the tetrapod data: @@ -206,12 +206,12 @@ library(palaeoverse) data(tetrapods) ``` -Then we'll subset our occurrences to only those for *Mesosaurus*: +Then we'll subset our occurrences to only those for *Diplocaulus*: ```r # Subset to desired group -tetrapods <- subset(tetrapods, genus == "Mesosaurus") +tetrapods <- subset(tetrapods, genus == "Diplocaulus") ``` Now, let's plot those occurrences on a world map. Here we use the `{geodata}` and `{raster}` packages to generate the map. Then we add colored points on top of this. Note that we use `alpha = 0.75` in case there are multiple occurrences in the same place. That way, the darker the color, the more occurrences in that geographic location. @@ -235,8 +235,8 @@ Now, as with the penguin figure above, we can easily replace those points with s ```r map("world", col = "lightgrey", fill = TRUE) -add_phylopic_base(name = "Mesosaurus", x = tetrapods$lng, y = tetrapods$lat, - ysize = 8, color = "blue", alpha = 0.75) +add_phylopic_base(name = "Diplocaulus", x = tetrapods$lng, y = tetrapods$lat, + ysize = 8, fill = "blue", alpha = 0.75) ```
diff --git a/vignettes/c-advanced-base.Rmd.orig b/vignettes/c-advanced-base.Rmd.orig index 4d18bec..47d432e 100644 --- a/vignettes/c-advanced-base.Rmd.orig +++ b/vignettes/c-advanced-base.Rmd.orig @@ -137,7 +137,7 @@ for (i in seq_along(species_split)) { } ``` -Finally, let's color the female and male penguins with different colors. We'll also add a legend to the last panel. +Finally, let's give the female and male penguins different fill colors. We'll also add a legend to the last panel. ```{r base-penguin-plot-5} par(mfrow = c(3, 1), mar = c(4, 4, 2, 1)) @@ -153,7 +153,7 @@ for (i in seq_along(species_split)) { y = species_data$flipper_length_mm, ysize = species_data$body_mass_g / max(penguins_subset$body_mass_g, na.rm = TRUE) * 8, - color = ifelse(species_data$sex == "male", "blue", "orange")) + fill = ifelse(species_data$sex == "male", "blue", "orange")) } # Add a legend to the last plot @@ -164,7 +164,7 @@ legend("bottomright", legend = c("Female", "Male"), pch = 20, Now that's a nice figure! # Geographic distribution -In much the same way as generic x-y plotting, the **rphylopic** package can be used in base R to plot organism silhouettes on a map. That is, to plot data points (e.g., species occurrences) as silhouettes. We provide an example here of how this might be achieved. For this application, we use the example occurrence dataset of early (Carboniferous to Early Triassic) tetrapods from the `{palaeoverse}` R package to visualize the geographic distribution of *Mesosaurus* fossils. +In much the same way as generic x-y plotting, the **rphylopic** package can be used in base R to plot organism silhouettes on a map. That is, to plot data points (e.g., species occurrences) as silhouettes. We provide an example here of how this might be achieved. For this application, we use the example occurrence dataset of early (Carboniferous to Early Triassic) tetrapods from the `{palaeoverse}` R package to visualize the geographic distribution of *Diplocaulus* fossils. First, let's load our libraries and the tetrapod data: @@ -177,11 +177,11 @@ library(palaeoverse) data(tetrapods) ``` -Then we'll subset our occurrences to only those for *Mesosaurus*: +Then we'll subset our occurrences to only those for *Diplocaulus*: ```{r} # Subset to desired group -tetrapods <- subset(tetrapods, genus == "Mesosaurus") +tetrapods <- subset(tetrapods, genus == "Diplocaulus") ``` Now, let's plot those occurrences on a world map. Here we use the `{geodata}` and `{raster}` packages to generate the map. Then we add colored points on top of this. Note that we use `alpha = 0.75` in case there are multiple occurrences in the same place. That way, the darker the color, the more occurrences in that geographic location. @@ -198,8 +198,8 @@ Now, as with the penguin figure above, we can easily replace those points with s ```{r base-geog-plot-2, fig.height = 5, warning = FALSE} map("world", col = "lightgrey", fill = TRUE) -add_phylopic_base(name = "Mesosaurus", x = tetrapods$lng, y = tetrapods$lat, - ysize = 8, color = "blue", alpha = 0.75) +add_phylopic_base(name = "Diplocaulus", x = tetrapods$lng, y = tetrapods$lat, + ysize = 8, fill = "blue", alpha = 0.75) ``` Snazzy! diff --git a/vignettes/ggplot-geog-plot-1-1.png b/vignettes/ggplot-geog-plot-1-1.png index 93f3dd6..04a1be9 100644 Binary files a/vignettes/ggplot-geog-plot-1-1.png and b/vignettes/ggplot-geog-plot-1-1.png differ diff --git a/vignettes/ggplot-geog-plot-2-1.png b/vignettes/ggplot-geog-plot-2-1.png index 236ec78..dc4a46f 100644 Binary files a/vignettes/ggplot-geog-plot-2-1.png and b/vignettes/ggplot-geog-plot-2-1.png differ diff --git a/vignettes/ggplot-geog-plot-3-1.png b/vignettes/ggplot-geog-plot-3-1.png index 605d54f..48375a1 100644 Binary files a/vignettes/ggplot-geog-plot-3-1.png and b/vignettes/ggplot-geog-plot-3-1.png differ diff --git a/vignettes/ggplot-penguin-plot-2-1.png b/vignettes/ggplot-penguin-plot-2-1.png index f23a023..090d899 100644 Binary files a/vignettes/ggplot-penguin-plot-2-1.png and b/vignettes/ggplot-penguin-plot-2-1.png differ diff --git a/vignettes/ggplot-penguin-plot-3-1.png b/vignettes/ggplot-penguin-plot-3-1.png index 6300b66..21e5aaa 100644 Binary files a/vignettes/ggplot-penguin-plot-3-1.png and b/vignettes/ggplot-penguin-plot-3-1.png differ diff --git a/vignettes/ggplot-penguin-plot-4-1.png b/vignettes/ggplot-penguin-plot-4-1.png index 3cb2017..4cd56bc 100644 Binary files a/vignettes/ggplot-penguin-plot-4-1.png and b/vignettes/ggplot-penguin-plot-4-1.png differ diff --git a/vignettes/ggplot-penguin-plot-5-1.png b/vignettes/ggplot-penguin-plot-5-1.png index 4a9eb80..c691998 100644 Binary files a/vignettes/ggplot-penguin-plot-5-1.png and b/vignettes/ggplot-penguin-plot-5-1.png differ diff --git a/vignettes/ggplot-penguin-plot-6-1.png b/vignettes/ggplot-penguin-plot-6-1.png index 89f5b3d..ea298c5 100644 Binary files a/vignettes/ggplot-penguin-plot-6-1.png and b/vignettes/ggplot-penguin-plot-6-1.png differ diff --git a/vignettes/ggplot-phylo-plot-3-1.png b/vignettes/ggplot-phylo-plot-3-1.png index 0c6f062..865490f 100644 Binary files a/vignettes/ggplot-phylo-plot-3-1.png and b/vignettes/ggplot-phylo-plot-3-1.png differ diff --git a/vignettes/ggplot-phylo-plot-4-1.png b/vignettes/ggplot-phylo-plot-4-1.png index a0804a9..da76011 100644 Binary files a/vignettes/ggplot-phylo-plot-4-1.png and b/vignettes/ggplot-phylo-plot-4-1.png differ diff --git a/vignettes/intro-base-plot-1.png b/vignettes/intro-base-plot-1.png index 5183f92..a0a8ccf 100644 Binary files a/vignettes/intro-base-plot-1.png and b/vignettes/intro-base-plot-1.png differ diff --git a/vignettes/intro-ggplot-plot-1.png b/vignettes/intro-ggplot-plot-1.png index 2726bb9..8f94660 100644 Binary files a/vignettes/intro-ggplot-plot-1.png and b/vignettes/intro-ggplot-plot-1.png differ diff --git a/vignettes/intro-transform-plot-1.png b/vignettes/intro-transform-plot-1.png index 68061c5..04e5ab5 100644 Binary files a/vignettes/intro-transform-plot-1.png and b/vignettes/intro-transform-plot-1.png differ