1

I want to create a horizontal histogram, and adjust the chart aspect ratio using ggplot2 .

For example let's say my chart is dia <- ggplot(diamonds, aes(x=color)) + geom_bar().

I can flip this to be horizontal using dia + coord_flip().

I can also adjust the aspect ratio e.g. dia + coord_fixed(ratio=.001).

But when I combine them dia + coord_flip()+ coord_fixed(ratio=.001), the chart is no longer horizontal.

Is there any way to achieve what I want using ggplot2?

Ricky
  • 4,616
  • 6
  • 42
  • 72
  • 1
    do you need the aspect ratio set with respect to the data (axes), or would adjusting the panel's aspect ratio be good enough? – baptiste May 03 '15 at 08:29

1 Answers1

5

See this answer on the ggplot2 mailing list :

You can only use one coord_*() function on a given ggplot since it changes the coordinate system after everything else has been done. To change the aspect ratio, you can use the corresponding argument in the theming system:

 + coord_flip() + theme(aspect.ratio = 1)
scoa
  • 19,359
  • 5
  • 65
  • 80
  • 3
    Is this answer correct? As far as I can tell the theme aspect ratio refers to the shape of the panel, while coord_fixed refers to that of the data. – mb7744 Feb 08 '17 at 13:49