Git Product home page Git Product logo

Comments (4)

teunbrand avatar teunbrand commented on July 30, 2024 1

Alright thanks for the interest anyway! Making examples strikes again as an excellent bugfix :)

from ggh4x.

teunbrand avatar teunbrand commented on July 30, 2024

There shouldn't be a conflict (not saying that there isn't). Could you provide some example with one of the built-in datasets of where this approach fails?

from ggh4x.

tombradferlawrence avatar tombradferlawrence commented on July 30, 2024

Thanks for such a prompt response. Here's some code. I might have been able to narrow down this issue. With this example it looks like the breaks are being set, but the limits are not being recognised. If I don't set any limits, the axes are restricted to the values in the data, and so there are no axes values if they aren't in that range. If I set only one of the limits and use 'NA' in the other, then that is ignored.

So, it looks like I need to manually set both the limits for this to work. Perhaps that is how the function is supposed to behave. Sorry if this is the case and I just didn't read the documentation correctly!

# Subet some example data
DATA <- mpg[mpg$manufacturer %in% c("dodge", "ford") & mpg$class %in% c("pickup", "suv"),]

# Set custom x axes breaks
CUSTOM.BREAKS <- list(
  scale_x_continuous(breaks = c(5, 6, 17, 23)), # Top left plot, will only plot data, no axes values
  scale_x_continuous(breaks = c(0, 10, 15, 20, 25), limits = c(0, NA)), # Top right plot, 
                                                                        honours the lower limit, 
                                                                        so shows '0' and '10' on the axes, but not 15+
  scale_x_continuous(breaks = c(0, 10, 15, 20, 25), limits = c(0, 25)), # Second from top on left, 
                                                                        shows full range of values.
  scale_x_continuous(breaks = c(5, 6, 17, 23)),
  scale_x_continuous(breaks = c(10, 20, 30)),
  scale_x_continuous(breaks = c(9, 10, 11, 12, 13, 14, 15, 16, 17, 18)),
  scale_x_continuous(breaks = c(11, 22, 33)),
  scale_x_continuous(breaks = c(8, 16, 24))
)

# Set strip theme
PLOT.STRIPS <- strip_nested(
  text_y = elem_list_text(
    colour = c(rep("white", 2), rep("black", 4))),
  background_y = elem_list_rect(
    fill = c("#210c4a", "#8a226a", rep(c("#bc3754", "#f9cb35"), 2))),
  by_layer_y = FALSE
)

# Plot
ggplot(DATA, aes(cty, hwy)) +
  geom_point() +
  facet_grid2(year + class ~ manufacturer, scales = "free", independent = "x", axes = "y", 
                         remove_labels = "y", strip = PLOT.STRIPS) +
  facetted_pos_scales(x = CUSTOM.BREAKS)
                

from ggh4x.

tombradferlawrence avatar tombradferlawrence commented on July 30, 2024

And after some more testing with my real data, I realise that nesting the facets will also change the plotting order I was expecting when setting the custom breaks.

Going to close this now. So sorry I posted before I realised I was doing something wrong. The package is working brilliantly.

from ggh4x.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.