向右移动geom_bar(不是居中对齐)

时间:2016-08-03 20:23:18

标签: r ggplot2

我有一个如下所示的条形图:

ggplot(mtcars, aes(x = cyl, y = hp)) + 
    geom_bar(stat = "identity", width = 1)

我想调整geom_bar参数,使条形图向右移动(不居中)......

enter image description here

1 个答案:

答案 0 :(得分:9)

试试这个:

ggplot(mtcars, aes(x = cyl, y = hp)) + 
 geom_bar(stat = "identity", width = 1, position = position_nudge(x = 0.5))

我是如何理解的:去了?geom_bar并看到有一个postion参数和?position_dodge的链接。查看那里的示例并对代码进行修改。似乎是一个令人满意的解决方案。

相关问题