使用ggplot2,我可以在轴上插入一个中断吗? [英] Using ggplot2, can I insert a break in the axis?

查看:198
本文介绍了使用ggplot2,我可以在轴上插入一个中断吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个条形图,其中一个值比其他值大得多。有没有一种不连续的Y轴?我的数据如下:

  df < -  data.frame(a = c(1,2,3,500),b = c(a1,a2,a3,a4))

p < - ggplot ()
p <-p + opts(axis.text.x = theme_text(angle = 90,hjust = 1))+ coord_flip()
p



有没有一种方法可以让我的轴运行从1到10,然后是490到500?我想不出任何其他绘制数据的方式(除了转换它,我不想这样做)。 解决方案

正如其他地方所指出的那样,这不是 ggplot2 可以很好地处理,因为破损的轴通常被认为是可疑的。



其他策略通常被认为是解决这个问题的更好的解决方案。布赖恩提到了一些(面向,两个关注不同的价值观)。人们经常忽略的另一种选择是,特别是对于barcharts,就是制作一个


看看实际值,500并不会掩盖差异在其他值!由于某些原因,表格没有得到足够的尊重,因为数据是可视化技术。你可能反对说你的数据有很多很多的类别,这些类别在表格中变得很笨重。如果是这样的话,很可能你的条形图将会有太多的条形图,以至于不太明智。



我并不是争辩所有表所有时间。但是,如果您制作的酒吧相对较少,那么他们肯定是要考虑的事情。如果你制作的酒吧条形图很多,你可能需要反思。



最后,还有 axis.break 函数在 plotrix 包中实现了破损的轴。但是,从我收集的内容中,您必须亲自指定轴标签和位置。


I want to make a bar plot where one of the values is much bigger than all other values. Is there a way of having a discontinuous y-axis? My data is as follows:

df <- data.frame(a = c(1,2,3,500), b = c('a1', 'a2','a3', 'a4'))

p <- ggplot(data = df, aes(x = b, y = a)) + geom_bar() 
p <- p + opts(axis.text.x=theme_text(angle= 90, hjust=1))  + coord_flip()
p

Is there a way that I can make my axis run from 1- 10, then 490 - 500? I can't think of any other way of plotting the data (aside from transforming it, which I don't want to do)

解决方案

As noted elsewhere, this isn't something that ggplot2 will handle well, since broken axes are generally considered questionable.

Other strategies are often considered better solutions to this problem. Brian mentioned a few (faceting, two plots focusing on different sets of values). One other option that people too often overlook, particularly for barcharts, is to make a table:

Looking at the actual values, the 500 doesn't obscure the differences in the other values! For some reason tables don't get enough respect as data a visualization technique. You might object that your data has many, many categories which becomes unwieldy in a table. If so, it's likely that your bar chart will have too many bars to be sensible as well.

And I'm not arguing for tables all the time. But they are definitely something to consider if you are making barcharts with relatively few bars. And if you're making barcharts with tons of bars, you might need to rethink that anyway.

Finally, there is also the axis.break function in the plotrix package which implements broken axes. However, from what I gather you'll have to specify the axis labels and positions yourself, by hand.

这篇关于使用ggplot2,我可以在轴上插入一个中断吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆