如何用ggplot生成非标准的情节类型?

时间:2012-04-04 19:21:00

标签: r ggplot2

我想制作一个与ggplot非常接近的情节(found here):

enter image description here

然而,我想绘制条件的范围而不是频率。这是我想要用5个条件生成的图的草图:

enter image description here

我的数据被安排为范围的起点和终点坐标。例如,对于条件5,范围的开始是30并且范围的结束是40(为了清楚起见,我在图中标记了这一点)。我的数据来自以下格式的文件:

id      start   end
1       20      35
2       60      75    
3       10      30
4       80      90
5       30      40

我想在一张图上以这种方式绘制大约100个开始值和结束值。最终的情节应该只有两种颜色。

更新:

为了将来的参考,Justin的解决方案产生了这个:

enter image description here

1 个答案:

答案 0 :(得分:13)

这样的事情:

library(ggplot2)
library(reshape)
dat <- data.frame(lets=letters[1:5], low=1:5, mid=3:7, high=10:14)
dat.melt <- melt(dat, id.vars='lets')


ggplot(dat.melt, aes(x=lets, y=value, fill=variable)) + 
  geom_bar(stat='identity') + 
  scale_fill_manual(breaks=c('low','mid','high'), values=c('blue','red','blue')) +
  coord_flip()

但完全依赖于您的数据...

相关问题