From 33a76c51172a378e33e6e58c675bcd473e35d5c7 Mon Sep 17 00:00:00 2001 From: Nathan Yang Date: Fri, 2 Aug 2024 07:39:03 -0700 Subject: [PATCH] Changes during the meeting + fixed rescale11y --- R/geom_segment_glyph.R | 10 +++++----- README.Rmd | 9 +++++---- vignettes/GeomSegmentGlyph.Rmd | 6 ++++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/R/geom_segment_glyph.R b/R/geom_segment_glyph.R index 04f9559..e2bf855 100644 --- a/R/geom_segment_glyph.R +++ b/R/geom_segment_glyph.R @@ -95,11 +95,11 @@ rescale01y <- function(y, yend, ylim=NULL) { return(list(y, yend)) } -rescale11y <- function(y, yend, ylim=NULL) { - #The rescale01x function can be used here because y and yend are agnostic - y = rescale01x(y) - yend = rescale01x(yend) * -1 - return(list(y,yend)) +rescale11y <- function(y, yend, xlim=NULL) { + newy = 2 * (rescale01y(y, yend)[[1]] - 0.5) + newyend = 2 * (rescale01y(y, yend)[[2]] - 0.5) + + return(list(newy, newyend)) } is.rel <- function(x) inherits(x, "rel") diff --git a/README.Rmd b/README.Rmd index 41342b1..f67087c 100644 --- a/README.Rmd +++ b/README.Rmd @@ -34,7 +34,7 @@ devtools::install_github("Knicey/stglyphs") This is a basic example which shows you how to solve a common problem: -```{r example, eval = FALSE} +```{r example} library(stglpyhs) grouped <- stations |> @@ -42,10 +42,11 @@ grouped <- stations |> summarise( avgmin = mean(tmin, na.rm = TRUE), avgmax = mean(tmax, na.rm = TRUE) -) + ) |> + ungroup() #TODO: Accommodate for xend aesthetic (required in geom_segment) -```` -```{r example, eval = FALSE} +``` +```{r example} ggplot(data = grouped) + geom_sf(data = mainland_us, color = "white") + ggthemes::theme_map() + diff --git a/vignettes/GeomSegmentGlyph.Rmd b/vignettes/GeomSegmentGlyph.Rmd index 70e57f9..c027f4a 100644 --- a/vignettes/GeomSegmentGlyph.Rmd +++ b/vignettes/GeomSegmentGlyph.Rmd @@ -17,6 +17,8 @@ knitr::opts_chunk$set( ```{r setup} library(stglpyhs) +library(dplyr) +library(ggplot2) ``` # GeomSegmentGlyph @@ -90,7 +92,7 @@ ggplot(data = grouped) + geom_point(aes(x = long, y = lat)) + geom_segment_glyph( x_scale = rescale11x, - y_scale = rescale11y, + y_scale = rescale01y, width = 2, height = 3, aes( @@ -111,7 +113,7 @@ ggplot(data = grouped) + geom_point(aes(x = long, y = lat)) + geom_segment_glyph( x_scale = rescale11x, - y_scale = rescale11y, + y_scale = rescale01y, global_rescale = FALSE, width = 2, height = 3,