2016-10-19 42 views
0

我正在重疊範圍的一些壓扁並想以可視化的初始數據(重疊),並將所得組(扁平)的方式如下:可視化重疊和不重疊的範圍

初始數據: enter image description here

結果集: enter image description here

是這樣的可能,R和,例如,GGPLOT2?

回答

2
read.table(header=TRUE, sep=",", text="color,start,end 
red,12.5,13.8 
blue,0.0,5.4 
green,2.0,12.0 
yellow,3.5,6.7 
orange,6.7,10.0", stringsAsFactors=FALSE) -> df 

library(ggplot2) 

df$color <- factor(df$color, levels=rev(df$color)) 

ggplot(df) + 
    geom_segment(aes(x=start, xend=end, y=color, yend=color, color=color), size=10) + 
    scale_x_continuous(expand=c(0,0)) + 
    scale_color_identity() + 
    labs(x=NULL, y=NULL) + 
    theme_minimal() + 
    theme(panel.grid=element_blank()) + 
    theme(axis.text.x=element_blank()) + 
    theme(plot.margin=margin(30,30,30,30)) 

enter image description here

上有SO顯示如何獲得Y標誌像你證明(我們不能做所有爲您的工作;-)

1

其他職位第二部分問題的答案可以在第一部分中使用@hrbrmstr的出色答案。我們可以用overplotting我們的優勢,並只需爲細分爲固定值(例如1,這其中「紅」)的y座標:

p <- ggplot(df) + 
    geom_segment(aes(x=start, xend=end, color=color), 
        y=1, yend=1, size=10) + 
    scale_x_continuous(expand=c(0,0)) + scale_color_identity() + 
    labs(x=NULL, y=NULL) + 
    theme_minimal() +theme(panel.grid=element_blank()) + 
    theme(axis.text.x=element_blank()) + 
    theme(plot.margin=margin(30,30,30,30)) 
print(p)