forked from cb4ds/cxplot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcx_geom_contour.R
63 lines (61 loc) · 2.08 KB
/
cx_geom_contour.R
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
cx_geom_contour <- function(gg, cx, t) {
if (missing(t)) {
t = 'GeomContour'
}
r = list(
graphType = ifelse((t == 'GeomContour' || t == 'GeomContourFilled'), "ScatterBubble2D", "Scatter2D"),
contourFilled = ifelse(t == 'GeomContour', FALSE, ifelse((t == 'GeomContourFilled' || t == 'GeomDensity2dFilled'), TRUE, FALSE))
)
a = as.array(c('bins', 'binwidth', 'breaks', 'contour_var'))
p = as.array(c('contourLevelNumber','contourLevelWidth', 'contourLevels', 'contourStat'))
for (i in 1:length(a)) {
if (!is.null(gg[[t]][[a[i]]])) {
r[[p[i]]] = gg[[t]][[a[i]]]
}
}
if (t == 'GeomRaster') {
r$showContourBands = FALSE
r$contourType = 'raster'
} else if (t == 'GeomPoint') {
r$showContourBands = FALSE
r$contourType = 'point'
} else {
r$contourType = 'normal'
}
if (!is.null(gg[[t]]$colour) || !is.null(gg[[t]]$fill)) {
if (!is.null(gg[[t]]$colour)) {
if (gg[[t]]$colour %in% names(gg$data)) {
r$afterRender = list(list("createContour",list(gg[[t]]$colour),list(NULL)))
} else {
r$contourBandsColor = gg[[t]]$colour
r$afterRender = list(list("createContour",list(NULL),list(NULL)))
}
} else {
if (gg[[t]]$fill %in% names(gg$data)) {
r$afterRender = list(list("createContour",list(gg[[t]]$fill),list(NULL)))
} else {
r$contourBandsColor = gg[[t]]$fill
r$afterRender = list(list("createContour",list(NULL),list(NULL)))
}
}
} else {
if ((t == "GeomContourFilled" || t == 'GeomDensity2dFilled' ) && !is.null(gg$facet)) {
r$afterRender = list(list("createContour",list(gg$facet),list(NULL)))
} else {
r$afterRender = list(list("createContour",list(NULL),list(NULL)))
}
}
if (t == "GeomContourFilled" || t == 'GeomDensity2dFilled') {
r$showContourBands = FALSE
}
if (!is.null(gg[[t]]$alpha)) {
r$contourFilledTransparency = gg[[t]]$alpha
}
r
}
cx_geom_contour_filled <- function (gg, cx) {
cx_geom_contour(gg, cx, "GeomContourFilled")
}
cx_geom_raster <- function (gg, cx) {
cx_geom_contour(gg, cx, "GeomRaster")
}