Coord_radial & bars - removing gap at "North" of polar coords

Morning folks - how do I produce the appearance of coord_polar() using coord_radial(). It seems like no matter what I try, I either end up with a bigger gap at the top (plot 2) or no gap at the top (plot 3).

library(ggplot2)

plt <-
  mtcars |>
  tibble::rownames_to_column() |>
  dplyr::slice_head(n = 10) |>
  ggplot(aes(x = rowname, y = mpg)) +
  geom_col(fill = "white", color = "red")

# equal gaps
plt + coord_polar()


# bonus beefy gap at top
plt + coord_radial()


# no gap at top at all!
plt + coord_radial(expand = F)

Created on 2024-11-22 with reprex v2.1.1

the default expand for discrete scales is 6%, so take half of that and you can do

plt + 
  coord_radial(
    start = 0.03,
    end = (2 * pi) - 0.03,
    expand = F)

Thanks for the reply - although that seems to leave a gap in the plot background:

library(ggplot2)

plt <-
  mtcars |>
  tibble::rownames_to_column() |>
  dplyr::slice_head(n = 10) |>
  ggplot(aes(x = rowname, y = mpg)) +
  geom_col(fill = "white", color = "red")

# equal gaps
plt + 
  coord_radial(
    start = 0.03,
    end = (2 * pi) - 0.03,
    expand = F) +
  theme_dark()

Created on 2024-11-22 with reprex v2.1.1

It seems like the way forward is expansion()!

library(ggplot2)

plt <-
  mtcars |>
  tibble::rownames_to_column() |>
  dplyr::slice_head(n = 10) |>
  ggplot(aes(x = rowname, y = mpg)) +
  geom_col(fill = "white", color = "red")

# equal gaps
plt + 
  coord_radial() +
  scale_x_discrete(expand = expansion(add = c(0.5, 0.5)))

Created on 2024-11-22 with reprex v2.1.1

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.