ggplot2 coord_flip删除空格

时间:2018-05-17 22:09:50

标签: r ggplot2 bar-chart

当我在ggplo2中使用coord_flip时使用此代码

# rotate to make more readable
p1 <- ggplot(mtcars, aes(x = row.names(mtcars), mpg)) +
        geom_bar(stat = "identity") +
        coord_flip() +
        ggtitle("Fig. A: Default rotated x-axis")

# order bars
p2 <- ggplot(mtcars, aes(x = reorder(row.names(mtcars), mpg), y = mpg)) +
        geom_bar(stat = "identity") +
        coord_flip() +
        ggtitle("Fig. B: Rotated ordered x-axis")

grid.arrange(p1, p2, ncol = 2)

我得到以下图表

我已经突出显示y轴旁边的空间,你可以帮我理解如何删除它。

0 个答案:

没有答案