tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.47k stars 2.02k forks source link

path + polar coord + single value = error #1035

Closed fdelaunay closed 9 years ago

fdelaunay commented 9 years ago

Hi,

I've detected an unexpected behavior. I've briefly browsed the issues and don't think it was reported yet. Please excuse me it was. Here is how to reproduce it:

d <- expand.grid(sectors = 1:2, facets = 1:2 )
d$value <- c(5,6,7, NA)

library(ggplot2)
g <- ggplot(d, aes(x=sectors)) + geom_path(stat='identity', aes(y=value, group=1)) + facet_wrap( ~ facets)

#ok
g
#crash
g + coord_polar()

I understand that polar plots must be used with extreme precautions but I though that this bug looks simple enough to be reported :)

ggplot rules!

François

BrianDiggs commented 9 years ago

With your example, I didn't get a crash, but I did get

> g + coord_polar()
Error: replacement has 1 row, data has 0
In addition: Warning message:
Removed 1 rows containing missing values (geom_path). 

It does seem like a bug.

fdelaunay commented 9 years ago

No, it doesn't properly "crash". But when executed by Shiny, it kills the application :(

SamGG commented 9 years ago

An error stops further execution.

IMHO it is a border effect bug. The polar code has certainly not been tested in that particular case where no path could be displayed. Adding a point to each path leads to "no crash" ;-)

d <- expand.grid(sectors = 1:3, facets = 1:2 )
d$value <- c(2,3,5,6,7, NA)

library(ggplot2)
g <- ggplot(d, aes(x=sectors)) + 
geom_path(stat='identity', aes(y=value, group=1)) + 
facet_wrap( ~ facets)

#ok
g
# NO MORE crash
g + coord_polar()
fdelaunay commented 9 years ago

@SamGG changing data is cheating :D

Other option is to remove a point ! it doesn't produce error when there is no point:

d <- expand.grid(sectors = 1:2, facets = 1:2 )
d$value <- c(5,6,NA, NA)

library(ggplot2)
g <- ggplot(d, aes(x=sectors)) + geom_path(stat='identity', aes(y=value, group=1)) + facet_wrap( ~ facets)

#ok
g
#error
g + coord_polar() 

I will post something on Shiny g-group to understand why this error stops Shiny, not others.