-
-
Save daranzolin/a0abca3ec87c53f1cd2614ece7c9391e to your computer and use it in GitHub Desktop.
geom that uses hearts instead of points.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
geom_heart <- function (mapping = NULL, data = NULL, stat = "identity", position = "identity", | |
..., parse = FALSE, nudge_x = 0, nudge_y = 0, check_overlap = FALSE, | |
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) | |
{ | |
if (!missing(nudge_x) || !missing(nudge_y)) { | |
if (!missing(position)) { | |
stop("Specify either `position` or `nudge_x`/`nudge_y`", | |
call. = FALSE) | |
} | |
position <- position_nudge(nudge_x, nudge_y) | |
} | |
layer(data = data, mapping = mapping, stat = stat, geom = GeomText, | |
position = position, show.legend = show.legend, inherit.aes = inherit.aes, | |
params = list(parse = parse, check_overlap = check_overlap, | |
na.rm = na.rm, label = sprintf('\u2665'), ...)) | |
} | |
library(ggplot2) | |
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Petal.Length)) + | |
geom_heart() + | |
scale_color_gradientn(colours = rainbow(5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment