Skip to content

rpkgs/gg.layers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5699a7a · Sep 4, 2024
Jun 27, 2024
Sep 4, 2024
Apr 14, 2023
Apr 18, 2024
Sep 4, 2024
Mar 27, 2024
Mar 4, 2022
Aug 13, 2024
Aug 13, 2024
Feb 27, 2022
Aug 13, 2024
Jan 13, 2024
Aug 13, 2024
Apr 12, 2023
Mar 4, 2022
Mar 4, 2022

Repository files navigation

gg.layers

R-CMD-check codecov CRAN

Installation

You can install the development version of gg.layers from GitHub with:

# install.packages("remotes")
remotes::install_github("rpkgs/gg.layers")

Document

Example

self-made colorbar

https://stackoverflow.com/questions/68440366/how-can-i-add-triangles-to-a-ggplot2-colorbar-in-r-to-indicate-out-of-bound-valu

library(gg.layers)
#> Registered S3 method overwritten by 'gg.layers':
#>   method       from  
#>   print.gtable gtable
library(ggplot2)
library(rcolors)

brk <- c(-Inf, -1, 0, 1, 3, 6, 9, Inf)
nbrk <- length(brk) - 1
cols <- get_color(rcolors$amwg256, nbrk)

g <- make_colorbar(
  at = brk, col = cols, height = 1,
  tck = 0.4,
  space = "right",
  legend.text.location = c(0.3, 0.5),
  legend.text.just = c(0.5, 0.5),
  # legend.text = list(fontfamily = "Times", cex = 1.1),
  hjust = 0.05
)
p <- ggplot(mtcars %>% subset(cyl == 4), aes(mpg, disp)) + geom_point() + 
    facet_wrap(~cyl) + 
    theme(legend.position = "none")
p + g

significant regions

data("d_trendPerc")
d_mask <- mutate(d_trendPerc, mask = perc <= 0.99) # %>% as.data.frame()

# 1. geom_signPoint
ggplot(data = d_mask, aes(x, y)) +
  geom_raster(aes(fill = perc)) +
  geom_signPoint(aes(mask = !mask), fact = 2, shape = 4)

# 2. geom_signHatch
ggplot() +
  geom_raster(data = d_trendPerc, aes(x, y, fill = perc)) +
  # geom_sf(data = shp) +
  geom_signHatch(data = d_mask, aes(x, y, mask = mask), color = "red")

# 3. stat_signPattern
ggplot() +
  geom_raster(data = d_trendPerc, aes(x, y, fill = perc)) +
  stat_signPattern(
    data = d_mask, aes(x, y, mask = mask),
    fill = "transparent", color = "red",
    pattern_density = 0.02
  )