ggplot geom_bar - '旋转和翻转'?

nzc*_*ops 4 r ggplot2

test <- data.frame(
    y=seq(18,41,1),
    x=24:1
)

ggplot(test, aes(y=y, x=x)) + geom_bar(stat="identity", aes(width=1)) + 
    opts( axis.text.x = theme_blank(), axis.ticks.x = theme_blank()) + 
    scale_x_continuous(breaks=NULL) + 
    coord_cartesian(ylim = c(17, 42))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

就旋转和翻转而言,我想这个图中的y轴是什么,沿着顶部是什么,x轴是右边的x轴.因此,条形图正在从图的右侧"出来",顶部最长/最高,底部最短.如果它顺时针旋转90度,然后翻转一条可以实现它的垂直线.

coord_flip()和scale_y_reverse()在正确的路径上走了一段路.

编辑:

我想这非常接近,只需要将y轴放到图的顶部即可.

ggplot(test, aes(y=y, x=x)) + geom_bar(stat="identity", aes(width=1)) + 
    opts(axis.text.y = theme_blank(), axis.ticks.y = theme_blank()) + 
    scale_x_continuous(breaks=NULL) + scale_y_reverse() + coord_flip()  + scale_x_reverse()
Run Code Online (Sandbox Code Playgroud)

And*_*rie 10

不完全是你描述的,但也许足够接近?

ggplot(test, aes(y=y, x=x)) + geom_bar(stat="identity", aes(width=1)) +
  coord_flip() +
  xlim(24, 1) +
  ylim(42, 0)
Run Code Online (Sandbox Code Playgroud)

诀窍是以相反的顺序使xlimylim参数.您的轴位置仍然是底部和左侧......

在此输入图像描述