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

annotation_scale and annotation_north_arrow appear in all facets #25

Closed
adrfantini opened this issue Nov 2, 2018 · 5 comments
Closed

Comments

@adrfantini
Copy link

I often do faceted plotting with ggplot.
However, if using facets with annotations, such as annotation_scale and annotation_north_arrow, appear on all facets. How would it be possible to make them appear only once, other than using patchwork or similar, instead of facets?

@paleolimbot
Copy link
Owner

As I've written it, there isn't any way to change or omit the properties of a scalebar or north arrow on panels using facets. This is something I should fix! In annotation_map_tile() I've made some of the parameters aesthetics, which I will probably do with the location and width_hint parameters for the scale and north arrow geometries. Thank you for reporting this!

@paleolimbot
Copy link
Owner

Alright! This will be in the next version using syntax something like this:

library(tidyverse)
library(ggspatial)
  
  df <- tibble::tibble(
    facet_var = c("one", "two", "three", "four"),
    data = list(data.frame(x = 0:4, y = -(0:4)))
  ) %>%
    tidyr::unnest()

  scale_params <- tibble::tibble(
    facet_var = c("one", "two", "three"),
    width_hint = 0.25,
    style = c("bar", "ticks", "bar"),
    location = c("bl", "tr", "tl"),
    unit_category = c("metric", "imperial", "metric"),
    text_col = c("black", "red", "blue"),
    line_col = c("black", "red", "blue")
  )

  ggplot(df) +
    geom_point(aes(x, y)) +
    annotation_scale(
      aes(width_hint = width_hint, style = style, location = location, unit_category = unit_category,
          text_col = text_col, line_col = line_col),
      data = scale_params,
      plot_unit = "m"
    ) +
    facet_wrap(~facet_var) +
    coord_fixed()

Created on 2018-12-14 by the reprex
package
(v0.2.0).

@adrfantini
Copy link
Author

Awesome, thanks!

@neellab-umd
Copy link

Hi There - I have been trying to get the code in your 12/14/2018 comment to work with my data and I have cannot for the life of me get it to work. I also do not see anything about facets in the help for version 1.1.7. Before I try to make a reprex with my data, I wanted to see if what was posted in 2018 is what was implemented to get a scale bar in only one facet.

@bappa10085
Copy link

bappa10085 commented Feb 16, 2024

What about annotation_north_arrow? How can we add the annotation_north_arrow and annotation_scale outside of the map?

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

4 participants