Skip to content

Commit 032ca6a

Browse files
committed
make S7 class_ggplot
1 parent 32ccdb2 commit 032ca6a

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Collate:
9494
'compat-plyr.R'
9595
'utilities.R'
9696
'aes.R'
97+
'all-classes.R'
9798
'utilities-checks.R'
9899
'legend-draw.R'
99100
'geom-.R'
@@ -202,10 +203,11 @@ Collate:
202203
'limits.R'
203204
'margins.R'
204205
'performance.R'
206+
'theme.R'
207+
'plot.R'
205208
'plot-build.R'
206209
'plot-construction.R'
207210
'plot-last.R'
208-
'plot.R'
209211
'position-.R'
210212
'position-collide.R'
211213
'position-dodge.R'
@@ -272,7 +274,6 @@ Collate:
272274
'stat-ydensity.R'
273275
'summarise-plot.R'
274276
'summary.R'
275-
'theme.R'
276277
'theme-defaults.R'
277278
'theme-current.R'
278279
'theme-sub.R'

R/all-classes.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
class_gg <- S7::new_class("gg", abstract = TRUE)
3+
class_scale <- S7::new_S3_class("Scale")
4+
class_guides <- S7::new_S3_class("Guides")
5+
class_coord <- S7::new_S3_class("Coord")
6+
class_facet <- S7::new_S3_class("Facet")
7+
class_layer <- S7::new_S3_class("Layer")
8+
class_scales_list <- S7::new_S3_class("ScalesList")
9+
class_layout <- S7::new_S3_class("Layout")
10+
class_ggproto <- S7::new_S3_class("ggproto")

R/plot.R

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
#' @include all-classes.R
2+
#' @include theme.R
3+
4+
class_ggplot <- S7::new_class(
5+
name = "ggplot", parent = class_gg,
6+
properties = list(
7+
data = S7::class_any,
8+
layers = S7::class_list,
9+
scales = class_scales_list,
10+
guides = class_guides,
11+
mapping = mapping,
12+
theme = theme,
13+
coordinates = class_coord,
14+
facet = class_facet,
15+
layout = class_layout,
16+
labels = labs,
17+
plot_env = S7::class_environment
18+
)
19+
)
20+
121
#' Create a new ggplot
222
#'
323
#' `ggplot()` initializes a ggplot object. It can be used to
@@ -120,19 +140,19 @@ ggplot.default <- function(data = NULL, mapping = aes(), ...,
120140

121141
data <- fortify(data, ...)
122142

123-
p <- structure(list(
143+
p <- class_ggplot(
124144
data = data,
125145
layers = list(),
126146
scales = scales_list(),
127147
guides = guides_list(),
128148
mapping = mapping,
129-
theme = list(),
149+
theme = theme(),
130150
coordinates = coord_cartesian(default = TRUE),
131151
facet = facet_null(),
132152
plot_env = environment,
133153
layout = ggproto(NULL, Layout),
134-
labels = list()
135-
), class = c("gg", "ggplot"))
154+
labels = labs()
155+
)
136156

137157
set_last_plot(p)
138158
p
@@ -153,7 +173,7 @@ ggplot.function <- function(data = NULL, mapping = aes(), ...,
153173
#' @keywords internal
154174
#' @export
155175
#' @name is_tests
156-
is.ggplot <- function(x) inherits(x, "ggplot")
176+
is.ggplot <- function(x) S7::S7_inherits(x, class_ggplot)
157177

158178
plot_clone <- function(plot) {
159179
p <- plot

0 commit comments

Comments
 (0)