Browse Source

coord_proj working with CRAN ggplot2

pull/38/head
boB Rudis 4 years ago
parent
commit
961bced1a0
No known key found for this signature in database GPG Key ID: 2A514A4997464560
3 changed files with 56 additions and 9 deletions
  1. +1
    -1
      DESCRIPTION
  2. +49
    -0
      R/coord_proj.r
  3. +6
    -8
      ggalt.Rproj

+ 1
- 1
DESCRIPTION View File

@ -51,7 +51,7 @@ Imports:
extrafont,
tibble,
plotly (>= 3.4.1)
RoxygenNote: 6.0.0
RoxygenNote: 6.0.1
VignetteBuilder: knitr
Collate:
'annotate_textp.r'


+ 49
- 0
R/coord_proj.r View File

@ -123,6 +123,55 @@ CoordProj <- ggproto("CoordProj", Coord,
diff(ranges$y.proj) / diff(ranges$x.proj)
},
train = function(self, scale_details) {
# range in scale
ranges <- list()
for (n in c("x", "y")) {
scale <- scale_details[[n]]
limits <- self$limits[[n]]
if (is.null(limits)) {
range <- scale$dimension(expand_default(scale))
} else {
range <- range(scale$transform(limits))
}
ranges[[n]] <- range
}
orientation <- self$orientation %||% c(90, 0, mean(ranges$x))
# Increase chances of creating valid boundary region
grid <- expand.grid(
x = seq(ranges$x[1], ranges$x[2], length.out = 50),
y = seq(ranges$y[1], ranges$y[2], length.out = 50)
)
ret <- list(x = list(), y = list())
# range in map
proj <- project4(self, grid$x, grid$y)$range
ret$x$proj <- proj[1:2]
ret$y$proj <- proj[3:4]
for (n in c("x", "y")) {
out <- scale_details[[n]]$break_info(ranges[[n]])
ret[[n]]$range <- out$range
ret[[n]]$major <- out$major_source
ret[[n]]$minor <- out$minor_source
ret[[n]]$labels <- out$labels
}
details <- list(
orientation = orientation,
x.range = ret$x$range, y.range = ret$y$range,
x.proj = ret$x$proj, y.proj = ret$y$proj,
x.major = ret$x$major, x.minor = ret$x$minor, x.labels = ret$x$labels,
y.major = ret$y$major, y.minor = ret$y$minor, y.labels = ret$y$labels
)
details
},
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
# range in scale


+ 6
- 8
ggalt.Rproj View File

@ -5,21 +5,19 @@ SaveWorkspace: No
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
UseSpacesForTab: Yes
NumSpacesForTab: 2
RnwWeave: Sweave
LaTeX: pdfLaTeX
PackageBuildArgs: --resave-data
PackageCheckArgs: --as-cran
PackageRoxygenize: rd,collate,namespace

Loading…
Cancel
Save