Flipping and maintaining aspect ratio of a chart i

2019-08-10 08:45发布

This question already has an answer here:

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?

标签: r ggplot2
1条回答
三岁会撩人
2楼-- · 2019-08-10 09:37

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)
查看更多
登录 后发表回答