87
87
# ' ggplot(mtcars, aes(factor(cyl), fill = factor(vs))) +
88
88
# ' geom_bar(position = position_dodge2(preserve = "total"))
89
89
position_dodge <- function (width = NULL , preserve = " total" , orientation = " x" ,
90
- reverse = FALSE , stackOverlap = " no" ) {
90
+ reverse = FALSE , stack_overlap = " no" ) {
91
91
check_bool(reverse )
92
92
ggproto(NULL , PositionDodge ,
93
93
width = width ,
94
94
preserve = arg_match0(preserve , c(" total" , " single" )),
95
95
orientation = arg_match0(orientation , c(" x" , " y" )),
96
- stackOverlap = arg_match0(stackOverlap , c(" no" ," byExtent " ," byCenter " )),
96
+ stack_overlap = arg_match0(stack_overlap , c(" no" ," by_extent " ," by_center " )),
97
97
reverse = reverse
98
98
)
99
99
}
@@ -105,7 +105,7 @@ position_dodge <- function(width = NULL, preserve = "total", orientation = "x",
105
105
PositionDodge <- ggproto(" PositionDodge" , Position ,
106
106
width = NULL ,
107
107
preserve = " total" ,
108
- stackOverlap = " no" ,
108
+ stack_overlap = " no" ,
109
109
orientation = " x" ,
110
110
reverse = NULL ,
111
111
default_aes = aes(order = NULL ),
@@ -138,7 +138,7 @@ PositionDodge <- ggproto("PositionDodge", Position,
138
138
139
139
list (
140
140
width = self $ width ,
141
- stackOverlap = self $ stackOverlap ,
141
+ stack_overlap = self $ stack_overlap ,
142
142
n = n ,
143
143
flipped_aes = flipped_aes ,
144
144
reverse = self $ reverse %|| % FALSE
@@ -183,7 +183,7 @@ PositionDodge <- ggproto("PositionDodge", Position,
183
183
184
184
# Dodge overlapping interval.
185
185
# Assumes that each set has the same horizontal position.
186
- pos_dodge <- function (df , width , n = NULL , stackOverlap = " no" ) {
186
+ pos_dodge <- function (df , width , n = NULL , stack_overlap = " no" ) {
187
187
if (is.null(n )) {
188
188
n <- vec_unique_count(df $ group )
189
189
}
@@ -208,13 +208,13 @@ pos_dodge <- function(df, width, n = NULL, stackOverlap = "no") {
208
208
df $ xmin <- df $ x - d_width / n / 2
209
209
df $ xmax <- df $ x + d_width / n / 2
210
210
211
- if (stackOverlap == " byExtent " ) {
211
+ if (stack_overlap == " by_extent " ) {
212
212
# The code chunk below is just to implement the following line without tidyverse functions, as ggplot2 can be imported without that
213
213
# df %>% group_by(group) %>% mutate(ymaxx = cumsum(ymax)) %>% mutate(ymin = ymaxx-ymax, ymax = ymaxx)
214
214
215
215
df $ ymaxx = NA # Initialize the variable. This will store the desired top of the group
216
- groupIDs = unique(df $ group ) # Collect the unique groupIDs. Thi
217
- for (gid in groupIDs ) {
216
+ group_ids = unique(df $ group ) # Collect the unique groupIDs. Thi
217
+ for (gid in group_ids ) {
218
218
df $ ymaxx [df $ group == gid ] = cumsum(df $ ymax [df $ group == gid ])
219
219
}
220
220
# Create the new y placements
@@ -223,14 +223,14 @@ pos_dodge <- function(df, width, n = NULL, stackOverlap = "no") {
223
223
224
224
df $ ymaxx = NULL # Remove the extra variable
225
225
226
- } else if (stackOverlap == " byCenter " ) {
226
+ } else if (stack_overlap == " by_center " ) {
227
227
# Similarly to above, the complicated code below is just to do the next line without tidyverse
228
228
# df %>% group_by(group) %>% mutate(extent = ymax-ymin, ymaxx = cumsum((ymax+ymin)/2)) %>% mutate(ymin = ymaxx-extent/2, ymax = ymaxx+extent/2)
229
229
230
230
df $ ymaxx = NA # Initialize the variable. This will store the desired top of the group
231
231
df $ extent = NA # Initialize the variable storing the extent of the geom
232
- groupIDs = unique(df $ group ) # Collect the unique groupIDs. Thi
233
- for (gid in groupIDs ) {
232
+ group_ids = unique(df $ group ) # Collect the unique groupIDs. Thi
233
+ for (gid in group_ids ) {
234
234
df $ ymaxx [df $ group == gid ] = cumsum((df $ ymax [df $ group == gid ] + df $ ymin [df $ group == gid ])/ 2 )
235
235
}
236
236
df $ extent = df $ ymax - df $ ymin
0 commit comments