Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggspatial reorders facets #108

Open
lucas-johnson opened this issue Nov 30, 2022 · 1 comment
Open

ggspatial reorders facets #108

lucas-johnson opened this issue Nov 30, 2022 · 1 comment

Comments

@lucas-johnson
Copy link

Thanks for an awesome package! I use this stuff all the time.

It appears that ggspatial reorders facets (alphabetically), which have a specific order as determined by the factor levels. It should maintain the facet ordering, especially when factors are used.

library(ggspatial)
packageVersion("ggspatial")
#> [1] '1.1.5'
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.1.2
packageVersion("ggplot2")
#> [1] '3.3.6'

data <- data.frame(x = 0:4, y = -(0:4))
data <- dplyr::bind_rows(
  data |> dplyr::mutate(facet = "c"),
  data |> dplyr::mutate(facet = "b"),
  data |> dplyr::mutate(facet = "a")
) |> dplyr::mutate(
  facet = factor(facet, levels = c('c', 'b', 'a'))
)

scale_params <- tibble::tibble(
  facet = c("a"),
  location = c("tl")
)

ggplot(data) + 
  geom_point(aes(x = x, y = y)) +
  annotation_scale(
    data = scale_params,
    aes(location = location)
  ) + 
  facet_wrap(~ facet)
#> Using plotunit = 'm'

ggplot(data) + 
  geom_point(aes(x = x, y = y)) +
  facet_wrap(~ facet)

Created on 2022-11-30 by the reprex package (v2.0.0)

@aakarner
Copy link

aakarner commented May 25, 2023

I just noticed this as well. It seems like it only happens when using something like scale_params to specify the facet where you'd like the scale placed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants