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

Add ability to name scales #50

Open
eliocamp opened this issue Sep 1, 2022 · 7 comments
Open

Add ability to name scales #50

eliocamp opened this issue Sep 1, 2022 · 7 comments

Comments

@eliocamp
Copy link
Owner

eliocamp commented Sep 1, 2022

From #48

A possible fix is to change the function to: new_scale("alpha", "some.name") instead of only adding the _new (or leaving it as the default behavior) and then using that name in the guides will probably work

@g-pacheco
Copy link

Hello @eliocamp,

I am sorry but I am not sure if I could not understand well what you suggested. Was it something like this? With this command I get the following error:

Error in new_scale("alpha", "Layka") : unused argument ("Layka")
  ggplot() +
  geom_raster(data = Salinity_df_r, aes(x = x, y = y, fill = Present.Surface.Salinity.Mean)) +
  scale_fill_viridis_c(option = "G", direction = -1) +
  geom_sf(data = Global, fill = "#fff7f3", colour = "#000000") +
  new_scale("alpha", "Layka") +
  geom_star(data = Coors_Grouped, aes(x = Longitude, y = Latitude, starshape = Group, fill = BioState),
            size = 6) +
  coord_sf(xlim = c(-11, 31), ylim = c(67, 49.75), expand = FALSE) +
  scale_starshape_manual(values = Shapes) +
  scale_x_continuous(breaks = seq(-10, 32, by = 10)) +
  scale_y_continuous(breaks = c(50, 58, 66)) +
  annotation_north_arrow(location = "br", which_north = "false", style = north_arrow_fancy_orienteering,
                         height = unit(2.5, "cm"), width = unit(3, "cm"),
                         pad_x = unit(2.75, "in"), pad_y = unit(.4, "in")) +
  annotation_scale(location = "br", line_width = 2, text_cex = 1.35, style = "ticks", pad_y = unit(.3, "in")) +
  theme(panel.background = element_blank(), 
        panel.border = element_rect(colour = "black", size = .5, fill = NA),
        panel.grid.major = element_line(color = "#000000", linetype = "dashed", size = .00005),
        plot.margin = margin(t = .005, b = .005, r = .2, l = .2, unit = "cm"),
        legend.background = element_rect(size = .15, color = "#000000", fill = "#fff7f3", linetype = "dotted"),
        legend.key = element_blank(),
        legend.position = c(.142, .8675),
        axis.title = element_blank(),
        axis.text = element_text(colour = "#000000", size = 15, face = "bold"),
        axis.ticks = element_line(color = "black", size = .5)) +
  guides(fill = guide_colourbar(title = "Salinity", title.theme = element_text(size = 16, face = "bold"),
                                label.theme = element_text(size = 14, face = "bold"), label.position = "top",
                                barwidth = 12.3, barheight = 1, order = 1, frame.linetype = 1, frame.colour = "#000000",
                                ticks.colour = "#ffffff", direction = "horizontal", reverse = TRUE, even.steps = TRUE,
                                draw.ulim = TRUE, draw.llim = TRUE),
         starshape = guide_legend(title = "Sampling Localities", title.theme = element_text(size = 16, face = "bold"),
                                  label.theme = element_text(size = 14),
                                  override.aes = list(starshape = Shapes, size = 4), order = 2))

Thanks in advance, George.

@eliocamp
Copy link
Owner Author

Yes, this is an idea that's not implemented.

In fact, after I opened the issue I realised that is not as easy to do because new_scale() renames the previous entries.

@g-pacheco
Copy link

I hope you will manage to find a solution. It would be great to have this option.

@eliocamp
Copy link
Owner Author

In the meantime, take a look at relayer, which already implements this but with a different syntax.

https://github.com/clauswilke/relayer

@eliocamp eliocamp changed the title Add ability of naming scales Add ability to name scales Oct 3, 2022
@rsh52
Copy link

rsh52 commented Apr 11, 2024

@eliocamp Great work on this package, it's helping out a lot with a plotting package I'm developing that requires separation of layers.

Wanted to check in on this and see if there's any plans to address, it would be very helpful for our workflow to have a renaming function. I realize how tricky this is in the context of ggplot's layering system, unfortunately we won't be using relayer since it isn't actively maintained.

@eliocamp
Copy link
Owner Author

This is not easy/possible right now due to how ggnewscale works. It might be possible after a future rewrite which will be possible once this ggplot2 issue is resolved via this PR.

@rsh52
Copy link

rsh52 commented Apr 15, 2024

Understood, I'll sub to both of those. Hopefully this is in the cards, would be incredibly useful and helpful! Thank you.

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

3 participants