2016-01-28 42 views
3

有很多酒吧图表的顶部边框看起来非常压扁,例如 -颜色只是geom_bar

ggplot(data.frame(x = 1:1000, y = (rnorm(1000)), fill = sample(c('a','b','c'), 1000, replace = T)), aes(x, y, fill = fill)) + geom_bar(stat = 'identity') 

我有一个类似的数据集,我觉得我能够做出更有意义的图表只需着色栏的顶部边框即可。我无法做到这一点。我能做的最接近的是geom_step,但是这也增加了y值变化的垂直线,这使得图表更加拥挤。尺寸不一定与x轴上的分离同步,因此它们会溢出到小侧值x。我能够想到的唯一可靠的解决方案就是实际操纵数据,以便我能够画出geom_segment s来为我完成我的工作。有没有其他方式

PS:我需要坚持这种格式的原因。

回答

2

您可以使用geom_errorbar()并将ymin=ymax=设置为您的y值。然后你可以使用width=size=来获得你需要的外观。

ggplot(data.frame(x = 1:1000, y = (rnorm(1000)), fill = sample(c('a','b','c'), 1000, replace = T))) + 
     geom_errorbar(aes(x=x,ymin=y,ymax=y,color=fill),size=0.5,width=3) 

enter image description here

相关问题