@@ -95,7 +95,7 @@ data_barplot = function(width = 5/6, beside = FALSE, center = FALSE, FUN = NULL,
9595 if (! is.factor(datapoints $ x )) datapoints $ x = factor (datapoints $ x )
9696 if (! is.null(xlevels )) {
9797 xlevels = if (is.numeric(xlevels )) levels(datapoints $ x )[xlevels ] else xlevels
98- if (any(is.na( xlevels ) ) || ! all(xlevels %in% levels(datapoints $ x ))) warning(" not all 'xlevels' correspond to levels of 'x'" )
98+ if (anyNA( xlevels ) || ! all(xlevels %in% levels(datapoints $ x ))) warning(" not all 'xlevels' correspond to levels of 'x'" )
9999 datapoints $ x = factor (datapoints $ x , levels = xlevels )
100100 }
101101 if (! is.null(xaxlabels )) levels(datapoints $ x ) <- xaxlabels
@@ -118,7 +118,7 @@ data_barplot = function(width = 5/6, beside = FALSE, center = FALSE, FUN = NULL,
118118 z [floor(mid ) + 1L ] = (mid - floor(mid )) * z [floor(mid ) + 1L ]
119119 sum(z [0L : floor(mid ) + 1L ], na.rm = TRUE )
120120 }
121- if (is.null(xlim )) xlim = c(1 , length(levels( datapoints $ x ) )) + c(- 0.5 , 0.5 ) * width
121+ if (is.null(xlim )) xlim = c(1 , nlevels( datapoints $ x )) + c(- 0.5 , 0.5 ) * width
122122 if (is.null(ylim )) ylim = if (beside || length(unique(datapoints $ by )) == 1L ) {
123123 c(pmin(0 , min(datapoints $ y , na.rm = TRUE ) * 1.02 ), pmax(0 , max(datapoints $ y , na.rm = TRUE ) * 1.02 ))
124124 } else {
@@ -143,8 +143,8 @@ data_barplot = function(width = 5/6, beside = FALSE, center = FALSE, FUN = NULL,
143143 datapoints = lapply(sdat , function (df ) {
144144
145145 df = df [order(df $ x ), , drop = FALSE ]
146- nx = length(levels( df $ x ) )
147- nb = length(levels( df $ by ) )
146+ nx = nlevels( df $ x )
147+ nb = nlevels( df $ by )
148148
149149 if (beside ) {
150150 xl = as.numeric(df $ x ) - width / 2 + (as.numeric(df $ by ) - 1 ) * width / nb * as.numeric(! facet_by )
0 commit comments