2014-04-07 3 views
4

오류 막대를 실제로 그래프에서 읽을 수 있도록 수정하려고합니다. 문제를 일으키는 유일한 것이 2013 년 데이터입니다. 어떻게해야합니까? 지터 (jitter) 또는 회피 (dodge)에 관한 게시물을 보았지만 문제를 해결하는 방법을 잘 모릅니다.ggplot에서 겹침 오류 막대 고정

YearlyDensity <- read.table(header=T, text=' 
Station Year  mean   se 
    M-25 2013 8944.444  3636.871 
    M-25 2008  4212   2371 
    M-25 2004  963   291 
    M-45 2013 8495.169  2111.072 
    M-45 2008  13023   1347 
    M-45 2004  8748   1740 
    X-2 2013 12345.411  1166.905 
')  

library(ggplot2) 
ggplot(YearlyDensity, aes(x=Year, y=mean, colour=Station,group=Station)) + 
    geom_errorbar(aes(ymin=mean-se, ymax=mean+se), colour="black", width=.2) + 
    geom_line(size=.8) + 
    geom_point(size=4, shape=18) + 
    coord_cartesian(ylim = c(0, 16000)) + 
    scale_y_continuous(breaks=seq(0,16000,2000)) + 
    xlab("Sampling Year") + 
    ylab("Mean Density") + 
    labs(fill="") + 
    theme_bw() + 
    theme(legend.justification=c(1,0), legend.position=c(1,0)) 

답변

3

당신은 같은 양의 dodge 모든 당신 geom의 필요, 즉 그들 각각에 position = position_dodge(width = the-desired-width)를 추가 : 여기

내가 변경을 시도하고있는 코드입니다.

# set desired dodge width 
pd <- position_dodge(width = 0.4) 

ggplot(YearlyDensity, aes(x = Year, y = mean, colour = Station, group = Station)) + 
    geom_errorbar(aes(ymin = mean-se, ymax = mean+se), 
       colour = "black", width = 0.2, position = pd) + 
    geom_line(size = .8, position = pd) + 
    geom_point(size = 4, shape = 18, position = pd) + 
    coord_cartesian(ylim = c(0, 16000)) + 
    scale_y_continuous(breaks = seq(0, 16000, 2000)) + 
    xlab("Sampling Year") + 
    ylab("Mean Density") + 
    labs(fill = "") + 
    theme_bw() + 
    theme(legend.justification = c(1, 0), legend.position = c(1, 0)) 
멋지다

enter image description here

+0

, 정말 고마워! – user3490557

+0

그것이 당신이 원했던 방식으로 효과가 있다는 것을 듣기 좋습니다! 건배. – Henrik

관련 문제