Skip to content

Report a bug of guide-bins: it cannot work with geom_sf. #3582

Closed
@microly

Description

@microly

The guide-bins seems cannot work with geom_sf.

Some examples:

For geom_point, both "coloursteps" and "bins" guides work well:

library(ggplot2)
library(tibble)

ggplot(tibble(x = 1:10, y = x, z = x), aes(x, y, fill = z)) +
    geom_point(shape = 21, size = 10) +
    scale_fill_stepsn(guide = "coloursteps", colours = terrain.colors(10))

p1

ggplot(tibble(x = 1:10, y = x, z = x), aes(x, y, fill = z)) +
    geom_point(shape = 21, size = 10) +
    scale_fill_stepsn(guide = "bins", colours = terrain.colors(10))

p2

But, for geom_sf, only "coloursteps" can work.
There seems to be a bug in guide-bins.

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"))

ggplot() +
    geom_sf(aes(fill = AREA), data = nc) +
    scale_fill_stepsn(guide = "coloursteps", colours = terrain.colors(10))

p3

ggplot() +
    geom_sf(aes(fill = AREA), data = nc) +
    scale_fill_stepsn(guide = "bins", colours = terrain.colors(10))

# Error in do.call("cbind", lapply(guide$geoms, function(g) g$data$size/10))[seq_len(n_keys),  : 
# subscript out of bounds

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions