0

In geom_bar() for argument "width=", it is possible to set it with units (like "mm") and not with a percentage of data resolution (the default)?

When I try with this code:

df<-data.frame("x" = rep(c("a","b","c","d"), times = 3),
               "y" = c(6,22,10,7,50,68,53,21,44,10,37,72),
               "group" = rep(c("gp1","gp2","gp3"),each=4))
ggplot(data = df,aes(x = x, y = y, fill = group))+
  geom_bar(aes(x = x, y = y, fill = group),
           width = unit(5, "mm"),
           stat = "identity")

It returns Error in Ops.unit(width, 2) : operator '/' not meaningful for units

  • 2
    Perhaps this post may provide some insight: [ggplot2 - The unit of size](https://stackoverflow.com/questions/17311917/ggplot2-the-unit-of-size) – Henrik Jun 14 '19 at 09:51
  • 1
    No, it's not possible. Also, check this post [What units are the 'width = ' in geom_bar(aes = ) and position_dodge(width = ) rendered in?](https://stackoverflow.com/questions/33877720/what-units-are-the-width-in-geom-baraes-and-position-dodgewidth-r) – pogibas Jun 14 '19 at 10:09
  • why you need this feature? – Roman Jun 14 '19 at 10:50

0 Answers0