Я надеюсь, что это решит вашу проблему:
gplot <- function(prd) {
ggplot() +
geom_polygon(data = shp.t,
aes_(x = ~long,
y = ~lat,
group = ~group),
fill = "white",
colour = "grey") +
## Plot errorbar
geom_errorbar(data = te10.cent,
size = 2,
colour = "red",
alpha = .8,
width = 0,
aes_(x = ~long.cent - 350,
ymin = ~lat.cent,
ymax = ~lat.cent + prd))
}
Воспроизводимый пример:
некоторые данные:
library(tidyverse)
data(iris)
iris %>%
group_by(Species) %>%
summarise_all(~mean(.)) -> summed_iris
gplot <- function(prd){
ggplot(summed_iris) +
geom_col(aes_(x = ~Species,
y = ~Sepal.Length))+
geom_errorbar(aes_(x = ~Species,
ymin = ~Sepal.Length -prd,
ymax = ~Sepal.Length + prd))
}
gplot(0.5)
![enter image description here](https://i.stack.imgur.com/iXP3z.png)
РЕДАКТИРОВАТЬ: к вопросу в комментарии:
В случае, когда prd
является именем столбца данных, возможно, лучше предварительно вычислить значения:
gplot <- function(prd){
ymin <- with(summed_iris, get("Sepal.Length") - get(prd))
ymax <- with(summed_iris, get("Sepal.Length") + get(prd))
summed_iris <- data.frame(summed_iris, ymin, ymax)
ggplot(summed_iris) +
geom_col(aes_(x = ~Species,
y = ~Sepal.Length))+
geom_errorbar(aes_(x = ~Species,
ymin = ~ymin,
ymax = ~ymax))
}
gplot("Petal.Length")
![enter image description here](https://i.stack.imgur.com/adqln.png)