File: helper-plot-data.R

package info (click to toggle)
r-cran-ggplot2 4.0.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 11,084 kB
  • sloc: sh: 15; makefile: 5
file content (26 lines) | stat: -rw-r--r-- 852 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Transform the data as the coordinate system does
cdata <- function(plot) {
  pieces <- ggplot_build(plot)

  lapply(pieces@data, function(d) {
    dapply(d, "PANEL", function(panel_data) {
      scales <- pieces@layout$get_scales(panel_data$PANEL[1])
      panel_params <- plot@coordinates$setup_panel_params(scales$x, scales$y, params = pieces@layout$coord_params)
      plot@coordinates$transform(panel_data, panel_params)
    })
  })
}

pranges <- function(plot) {
  layout <- ggplot_build(plot)@layout

  x_ranges <- lapply(layout$panel_scales_x, function(scale) scale$get_limits())
  y_ranges <- lapply(layout$panel_scales_y, function(scale) scale$get_limits())


  npscales <- plot@scales$non_position_scales()
  npranges <- lapply(npscales$scales$scales, function(scale) scale$get_limits())


  c(list(x = x_ranges, y = y_ranges), npranges)
}