Skip to content

Commit

Permalink
Merge branch 'my.head'
Browse files Browse the repository at this point in the history
  • Loading branch information
aphalo committed Feb 1, 2024
2 parents a361b80 + 3a24944 commit 13df4c2
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/geom-margin-arrow.r
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#' @examples
#' p <- ggplot(mtcars, aes(wt, mpg)) +
#' geom_point()
#' p
#' p + geom_x_margin_arrow(xintercept = 3.5)
#' p + geom_y_margin_arrow(yintercept = c(18, 28, 15))
#' p + geom_x_margin_arrow(data = data.frame(x = c(2.5, 4.5)),
#' mapping = aes(xintercept = x))
Expand Down
3 changes: 3 additions & 0 deletions R/geom-margin-grob.r
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
#' @examples
#' # We can add icons to the margin of a plot to signal events
#'
#'
#'
#'
geom_x_margin_grob <- function(mapping = NULL, data = NULL,
stat = "identity", position = "identity",
...,
Expand Down
2 changes: 2 additions & 0 deletions R/geom-margin-point.r
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#' @examples
#' p <- ggplot(mtcars, aes(wt, mpg)) +
#' geom_point()
#' p
#' p + geom_x_margin_point(xintercept = 3.5)
#' p + geom_y_margin_point(yintercept = c(18, 28, 15))
#' p + geom_x_margin_point(data = data.frame(x = c(2.5, 4.5)),
#' mapping = aes(xintercept = x))
Expand Down
12 changes: 12 additions & 0 deletions R/geom-quadrant-lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
#' geom_point()
#'
#' ggplot(my.data, aes(x, y)) +
#' geom_quadrant_lines(linetype = "dotted") +
#' geom_point()
#'
#' ggplot(my.data, aes(x, y)) +
#' geom_quadrant_lines(xintercept = 50,
#' yintercept = 10,
#' colour = "blue") +
Expand All @@ -77,6 +81,14 @@
#'
#' ggplot(my.data, aes(x, y)) +
#' geom_vhlines(xintercept = c(25, 50, 75),
#' yintercept = 10 ,
#' linetype = "dotted",
#' colour = "red") +
#' geom_point() +
#' theme_bw()
#'
#' ggplot(my.data, aes(x, y)) +
#' geom_vhlines(xintercept = c(25, 50, 75),
#' yintercept = c(10, 8),
#' linetype = "dotted",
#' colour = "red") +
Expand Down
9 changes: 9 additions & 0 deletions R/geom-table.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@
#' arrow = arrow(length = unit(0.5, "lines"))) +
#' theme_classic()
#'
#' # Using native plot coordinates instead of data coordinates
#' dfnpc <- tibble(x = 0.95, y = 0.95, tb = list(tb))
#'
#' ggplot(mtcars,
#' aes(wt, mpg, colour = factor(cyl))) +
#' geom_point() +
#' geom_table_npc(data = dfnpc,
#' aes(npcx = x, npcy = y, label = tb))
#'
geom_table <- function(mapping = NULL, data = NULL,
stat = "identity", position = "identity",
...,
Expand Down
37 changes: 37 additions & 0 deletions R/geom-text-linked.r
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,19 @@
#' geom_text_s(hjust = "left", nudge_x = 0.12) +
#' expand_limits(x = 6.2)
#' p +
#' geom_text_s(nudge_y = 0.1, nudge_x = 0.07) +
#' expand_limits(x = 6.2)
#' p +
#' geom_text_s(nudge_y = 1, angle = 90) +
#' expand_limits(y = 30)
#' p +
#' geom_text_s(angle = 90, nudge_y = 1,
#' arrow = arrow(length = grid::unit(1.5, "mm")),
#' colour.target = "segment", colour = "red") +
#' expand_limits(y = 30)
#' p +
#' geom_text_s(angle = 90, nudge_y = 1,
#' arrow = arrow(length = grid::unit(1.5, "mm")),
#' alpha.target = "segment", alpha = 0.3) +
#' expand_limits(y = 30)
#'
Expand All @@ -218,6 +226,12 @@
#' p +
#' geom_label_s(hjust = "outward_1", nudge_x = 0.12) +
#' expand_limits(x = 6.2)
#' p +
#' geom_label_s(hjust = "inward_3", nudge_y = 0.4)
#'
#' p +
#' geom_label_s(nudge_y = 1, angle = 90) +
#' expand_limits(y = 30)
#'
#' # Add aesthetic mappings and adjust arrows
#' p +
Expand Down Expand Up @@ -246,6 +260,24 @@
#' expand_limits(y = 27)
#'
#' p +
#' geom_label_s(aes(colour = factor(cyl)),
#' nudge_x = 0.3,
#' arrow = arrow(angle = 20,
#' length = grid::unit(1/3, "lines"))) +
#' scale_colour_discrete(l = 40) + # luminance, make colours darker
#' expand_limits(x = 7)
#'
#' p +
#' geom_label_s(aes(colour = factor(cyl)),
#' nudge_x = 0.3,
#' colour.target = c("box", "segment"),
#' linewidth = 0.6,
#' arrow = arrow(angle = 20,
#' length = grid::unit(1/3, "lines"))) +
#' scale_colour_discrete(l = 40) + # luminance, make colours darker
#' expand_limits(x = 7)
#'
#' p +
#' geom_label_s(aes(colour = factor(cyl), fill = factor(cyl)),
#' nudge_x = 0.3,
#' alpha.target = "box",
Expand All @@ -256,6 +288,11 @@
#' scale_colour_discrete(l = 40) + # luminance, make colours darker
#' expand_limits(x = 7)#' # Scale height of text, rather than sqrt(height)
#'
#' p +
#' geom_text_s(aes(size = wt), nudge_x = -0.1) +
#' scale_radius(range = c(3,6)) + # override scale_area()
#' expand_limits(x = c(1.8, 5.5))
#'
geom_text_s <- function(mapping = NULL,
data = NULL,
stat = "identity",
Expand Down
5 changes: 5 additions & 0 deletions R/geom-text-npc.r
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
#' geom_point() +
#' geom_text_npc(data = df, aes(npcx = x, npcy = y, label = text))
#'
#' ggplot(data = mtcars, mapping = aes(wt, mpg)) +
#' geom_point() +
#' geom_text_npc(data = df, aes(npcx = x, npcy = y, label = text)) +
#' expand_limits(y = 40, x = 6)
#'
#' ggplot(data = mtcars) +
#' geom_point(mapping = aes(wt, mpg)) +
#' geom_label_npc(data = df, aes(npcx = x, npcy = y, label = text))
Expand Down
33 changes: 33 additions & 0 deletions R/geom-text-pairwise.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@
#' parse = TRUE)
#'
#' p1 +
#' geom_text_pairwise(data = my.pairs,
#' aes(xmin = A, xmax = B,
#' y = bar.height,
#' label = sprintf("italic(P)~`=`~%.2f", p.value)),
#' arrow = grid::arrow(angle = 90,
#' length = unit(1, "mm"),
#' ends = "both"),
#' parse = TRUE)
#'
#' p1 +
#' geom_text_pairwise(data = my.pairs,
#' aes(xmin = A, xmax = B,
#' y = bar.height,
#' label = sprintf("italic(P)~`=`~%.2f", p.value)),
#' colour = "red",
#' arrow = grid::arrow(angle = 90,
#' length = unit(1, "mm"),
#' ends = "both"),
#' parse = TRUE)
#'
#' p1 +
#' geom_label_pairwise(data = my.pairs,
#' aes(xmin = A, xmax = B,
#' y = bar.height,
Expand Down Expand Up @@ -216,6 +237,18 @@
#' y = bar.height, label = text))
#'
#' p2 +
#' geom_text_pairwise(data = my.ranges,
#' aes(xmin = A, xmax = B,
#' y = bar.height, label = text),
#' angle = 90, hjust = -0.1)
#'
#' p2 +
#' geom_label_pairwise(data = my.ranges,
#' aes(xmin = A, xmax = B,
#' y = bar.height, label = text),
#' angle = 90, hjust = -0.1)
#'
#' p2 +
#' geom_label_pairwise(data = my.ranges,
#' aes(xmin = A, xmax = B,
#' y = bar.height, label = text))
Expand Down

0 comments on commit 13df4c2

Please sign in to comment.