Вот одна идея. Мы можем использовать ggplot2
для построения графика данных. Перед построением графика нам необходимо вычислить верхнюю и нижнюю границы ошибки avg_rate
плюс / минус и сохранить результаты в двух новых столбцах.
Вот коды для предварительной обработки данных. Я удалил эти записи с помощью NA
в avg_rate
.
library(dplyr)
library(ggplot2)
dat2 <- dat %>%
mutate(High = avg_rate + ER, Low = avg_rate - ER) %>%
mutate(Year = factor(Year)) %>%
filter(!is.na(avg_rate))
. Мы можем построить данные, используя Year
по оси x, avg_rate
по оси y и facet_grid
на основании Site
. Мы можем построить данные в виде точки и добавить панель ошибок, используя geom_errorbar
ggplot(dat2, aes(x = Year, y = avg_rate)) +
geom_point() +
geom_errorbar(aes(ymax = High, ymin = Low)) +
facet_grid(. ~ Site)

DATA
dat <- read.table(text = " Estuary Site Year avg_rate ER
1 'Fortrose Estuary' 'Northern Flats Sediment' 2018 NA NaN
2 'Fortrose Estuary' 'Northern Flats Sediment' 2019 -0.6666667 3.7107951
3 'Fortrose Estuary' 'Site A Sediment' 2019 NA NaN
4 'Fortrose Estuary' 'Site B Sediment' 2009 NA NaN
5 'Fortrose Estuary' 'Site B Sediment' 2011 -2.7500000 3.5707142
6 'Fortrose Estuary' 'Site B Sediment' 2012 -1.5000000 6.7577116
7 'Fortrose Estuary' 'Site B Sediment' 2013 1.5000000 3.8729833
8 'Fortrose Estuary' 'Site B Sediment' 2015 -0.6625000 3.7063853
9 'Fortrose Estuary' 'Site B Sediment' 2016 4.0750000 2.6612967
10 'Fortrose Estuary' 'Site B Sediment' 2018 -4.5000000 0.8164966
11 'Fortrose Estuary' 'Site B Sediment' 2019 6.9000000 4.2237424",
header = TRUE, stringsAsFactors = FALSE)