Skip to content

Harmonize width and location of horizontal bars across facets with different number of bars #4174

@werkstattcodes

Description

@werkstattcodes

First, many thanks again to everyone involved with this wonderful package.

I regularly make plots like the one below. While it conveys all the necessary info, its format is (imho) not really fit for publication.

What bothers me is that
a) bar widths are not the same (=should all have the width of the bars in the facet with most bars, i.e. europe),
b) that the bars in the different facets are not horizontally aligned (i.e. the bar BR in the facet south america should have the same vertical position as the bar ES in the facet europe). I would have hoped that facet_row would do the trick, but it seems not to be the case.

I might be mistaken, but it seems to me that the plot below is a fairly regularly required format. It would be great if there is a convenient way to produce it.

Many thanks!

library(tidyverse)
df <- data.frame(
  stringsAsFactors = FALSE,
         continent = c("europe","europe","europe",
                       "europe","asia","asia","asia","south america"),
           country = c("AT", "DE", "DK", "ES", "PK", "IN", "TW", "BR"),
             value = c(10L, 15L, 20L, 25L, 17L, 17L, 13L, 5L)
)

df %>% 
  ggplot()+
  geom_bar(aes(y=country,
               x=value),
           orientation = "y",
           stat="identity")+
  facet_wrap(vars(continent),
             scales = "free_y")

Created on 2020-08-16 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions