# size in geom_point using variable with all but 1 as NAs #985

Closed
opened this issue Jul 10, 2014 · 3 comments
Closed

# size in geom_point using variable with all but 1 as NAs#985

opened this issue Jul 10, 2014 · 3 comments

### iagomosqueira commented Jul 10, 2014

 When passing a variable in the data.frame to the size argument in geom_point, if the column to be all but one as NA, all values get plotted equally, i.e. NAs are not dropped. If two non-NA values exist, the plot looks as expected. Wanted to know if it is an unavoidable consequence of how size is calculated, or really a bug. It the later I could try finding/fixing it. ``` df <- data.frame(year=rep(10:14, each=3), age=1:3, data=runif(15)) # points sized as expected ggplot(df, aes(year, age)) + geom_point(aes(size=data)) # convert all values but 2 into NAs df\$data[1:13] <- NA #2 points sized and shown ggplot(df, aes(year, age)) + geom_point(aes(size=data), na.rm=TRUE) # convert all but one value into NA df\$data[1:14] <- NA # plot shows equal-sized dots for all datapoints ggplot(df, aes(year, age)) + geom_point(aes(size=data), na.rm=TRUE)``` I tried with different names for the data column, but it made no difference. Tested in both ggplot2 1.0.0 from CRAN and 1.0.0.99 from github. Thanks

### hadley commented Jun 12, 2015

 That is a strange one. I'll take a look. Even more minimal reprex: ```df <- data.frame(x = rep(1:2, each = 2), y = rep(1:2, 2), z = c(1, NA, NA, NA)) ggplot(df, aes(x, y, size = z)) + geom_point()```

### hadley commented Jul 23, 2015

 Ah, this is a bug in `scales::rescale()`: ```function(x, to = c(0, 1), from = range(x, na.rm = TRUE)) { if (zero_range(from) || zero_range(to)) return(rep(mean(to), length(x))) (x - from) / diff(from) * diff(to) + to }``` If `from` has `zero_range()`, it needs to preserve missing values in `x`.

### hadley commented Jul 23, 2015

 Fixed by r-lib/scales@b481ee2