Уклоняйтесь от полос ошибок и точек, чтобы избежать перекрытия

Я пытаюсь исправить полосы ошибок, чтобы их можно было прочитать на моем графике. Единственное, что вызывает проблемы, — это данные за 2013 год. Как мне это сделать? Я видел несколько сообщений о дрожании или уклонении, но я не уверен, как применить это, чтобы решить мою проблему.

Вот код, который я пытаюсь изменить:

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))

person user3490557    schedule 07.04.2014    source источник


Ответы (1)


Вы должны установить dodge width на одно и то же значение для всех geom, т.е. добавить position = position_dodge(width = <the-desired-width>) к каждому из них. См. Что такое аргумент ширины в position_dodge? для подробностей.

# 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))

введите здесь описание изображения

person Henrik    schedule 07.04.2014