Giter Site home page Giter Site logo

Comments (4)

davidhodge931 avatar davidhodge931 commented on June 12, 2024

For horizontal plots with multiple layers, it will work better if you make it vertically and then use coord_flip

from ggblanket.

davidhodge931 avatar davidhodge931 commented on June 12, 2024

Option A: magic + coord_flip if adding layers
Option B: No magic + everything works

from ggblanket.

davidhodge931 avatar davidhodge931 commented on June 12, 2024

This relates to 411 in scales

from ggblanket.

davidhodge931 avatar davidhodge931 commented on June 12, 2024
  1. If users are building a horizontal plot that includes multiple geoms, it is recommended that users build the plot vertically with ggblanket - and then use ggplot2::coord_flip to make it horizontally.

Users need to ensure that the scales built by their gg_* function are appropriate for subsequent layers. Plot scales are built by the gg_* function based on the data, x, y, *_limits, *_include, stat, position and coord arguments in the gg_* function.

# ggblanket + ggplot2
d <- penguins2 |>
  group_by(species) |>
  summarise(body_mass_g = mean(body_mass_g)) |>
  mutate(lower = body_mass_g * 0.95) |> 
  mutate(upper = body_mass_g * 1.2)

p1 <- d |>
  gg_col(
    x = species,
    y = body_mass_g,
    col = species,
    width = 0.75,
    y_include = c(0, max(d$upper)), 
    y_labels = \(x) x / 1000, 
    y_title = "Body mass kg",
    x_gridlines = TRUE, 
    y_gridlines = FALSE,
    col_legend_place = "n") +
  geom_errorbar(aes(ymin = lower, ymax = upper), 
                colour = "black",
                width = 0.1) +
  coord_flip()

p2 <- d |>
  gg_col(
    x = species,
    y = body_mass_g,
    col = species,
    colour = "#d3d3d3",
    fill = "#d3d3d3",
    width = 0.75,
    y_include = c(0, max(d$upper)), 
    y_labels = \(x) x / 1000, 
    y_title = "Body mass kg",
    x_gridlines = TRUE, 
    y_gridlines = FALSE,
    col_legend_place = "n") +
  geom_errorbar(aes(ymin = lower, ymax = upper), 
                width = 0.1) +
  coord_flip()

p1 / p2

from ggblanket.

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.