2016-07-02 9 views
2

가 여기 내 재현 예입니다 : 나는에 대한 해결책을 찾을 수 없습니다이산 y 값을 피하다, geom_segment()

library(ggplot2) 
p <- ggplot(data = IND.factions, aes(y = Country)) + 
    geom_segment(aes(x = StartDate, xend = EndDate, yend = Country, color = Origin), size = 10, position = position_dodge(width = 10)) 
p 

:

IND.factions <- rbind(c("Mughal Empire", "IND", "1526-1-1", "1857-1-1", "IND"), 
        c("Maratha Empire", "IND", "1674-1-1", "1818-1-1", "IND"), 
        c("Vijayanagara Empire", "IND", "1336-1-1", "1646-1-1", "IND"), 
        c("Deccan Sultanates", "IND", "1527-1-1", "1686-1-1", "IND"), 
        c("Bahmani Sultanate", "IND", "1347-1-1", "1527-1-1", "IND"), 
        c("EIC", "IND", "1612-1-1", "1757-1-1", "ENG"), 
        c("Company Rule", "IND", "1757-1-1", "1858-1-1", "ENG"), 
        c("Maratha Empire", "IND", "1858-1-1", "1947-1-1", "ENG") 
       ) 

IND.factions <- data.frame(IND.factions, stringsAsFactors = FALSE) 
names(IND.factions) <- c("Person", "Country", "StartDate", "EndDate", "Origin") 
IND.factions$StartDate <- as.Date(IND.factions$StartDate, "%Y-%m-%d") 
IND.factions$EndDate <- as.Date(IND.factions$EndDate, "%Y-%m-%d") 

내가 시각화하고자하는 타임 라인 같은 것입니다 겹치는 부분을 피하고 누구나 해결 방법을 염두에두고 있습니까? 물론 은 내가 다른 요인으로 그것을 분할 수 있다는 것을 알고,하지만

+0

. x와 y 값을 바꿀 수 있고'coord_flip'을 사용할 수 있습니다. 그러나 그것은 전체 세그먼트가 아닌 동일한 점만 피할 수 있습니다. 너에게 약간의 수작업이 필요하다고 생각해. 왜 y 값에'Person'을 사용하지 않습니까? – Roland

+0

'국가'에 대해 여러 값을 사용하려고합니까? –

+0

아니요,이 세그먼트의 경우 '국가'에 대해 하나의 값만 있습니다. 전체 음모에는 다른 국가들과 함께 여러 세그먼트가 포함됩니다. –

답변

1

는 지금까지 내가 아는 한, geom_segment은 피하고 허용하지 않습니다 단지 내 "worstcase"해결책이 될 것이지만, geom_linerange 않습니다.

library(ggplot2) 

IND.factions <- rbind(c("Mughal Empire", "IND", "1526-1-1", "1857-1-1", "IND"), 
        c("Maratha Empire", "IND", "1674-1-1", "1818-1-1", "IND"), 
        c("Vijayanagara Empire", "IND", "1336-1-1", "1646-1-1", "IND"), 
        c("Deccan Sultanates", "IND", "1527-1-1", "1686-1-1", "IND"), 
        c("Bahmani Sultanate", "IND", "1347-1-1", "1527-1-1", "IND"), 
        c("EIC", "IND", "1612-1-1", "1757-1-1", "ENG"), 
        c("Company Rule", "IND", "1757-1-1", "1858-1-1", "ENG"), 
        c("Maratha Empire", "IND", "1858-1-1", "1947-1-1", "ENG") 
       ) 

IND.factions <- data.frame(IND.factions, stringsAsFactors = FALSE) 
names(IND.factions) <- c("Person", "Country", "StartDate", "EndDate", "Origin") 
IND.factions$StartDate <- as.Date(IND.factions$StartDate, "%Y-%m-%d") 
IND.factions$EndDate <- as.Date(IND.factions$EndDate, "%Y-%m-%d") 



ggplot(data = IND.factions, aes(x = Country, ymin = StartDate, ymax = EndDate, 
           color = Origin, group = Person)) + 
    geom_linerange(size = 10, position = position_dodge(.33)) + 
    coord_flip() 
내가 당신을 도울 것입니다 피하고 생각하지 않는다

enter image description here

+1

고맙습니다. 또한 이미 논의 된 http://stackoverflow.com/questions/35322919/grouped-data-by-fact-with-geom-segment?lq=1 –

+1

일반적으로 말해서 그것은 'geom_segment'가 더 많은 것 같습니다 (예 : 산점도의 두 점 사이에서) 임의의 선이 될 수 있습니다.이 유형의 작업에는'geom_linerange'가 만들어졌습니다. –

+0

[여기] (http://stackoverflow.com/questions/21904364/how-to-jitter-dodge-geom-segments-so-they-remain-parallel/21922792#21922792) –