I am trying to plot using geom_errorbar() but the ggplot display geom_linerange() looking plot instead. I tried to reproduce an exact example dataset structure as my dataset but the example code below was able to correctly plot geom_errorbar(). The only difference is that my dataset's variability (sd, standard deviation) is quite small at many timepoints. However, even when I tweak and decrease the example dataset variability by 100 fold DV_sd = sd(conc)/100
, it still displays correctly geom_errorbar(). I am not sure why I am unable to plot geom_errorbar() on my actual dataset as it continues to look like geom_linerange().
library(tidyverse)
data(Indometh)
Indometh1 <- Indometh %>%
mutate(conc = conc * 1) %>%
mutate(Subject = as_numeric(Subject) + 0) %>%
mutate(Group = "Group 1")
Indometh2 <- Indometh %>%
mutate(conc = conc * 10) %>%
mutate(Subject = as_numeric(Subject) + 6) %>%
mutate(Group = "Group 2")
Indometh3 <- Indometh %>%
mutate(conc = conc * 100) %>%
mutate(Subject = as_numeric(Subject) + 6*2) %>%
mutate(Group = "Group 3")
Indometh_combine <- bind_rows(Indometh1, Indometh2, Indometh3)
Indometh_summary <- Indometh_combine %>%
group_by(Group, time) %>%
summarize(DV_mean = mean(conc),
DV_sd = sd(conc) ) %>%
ungroup()
Indometh_summary %>%
ggplot(aes(x = time, y = DV_mean, ymin = DV_mean - DV_sd, ymax = DV_mean + DV_sd, color = Group)) +
geom_point() +
geom_line() +
geom_errorbar(width = 0.25) +
scale_y_continuous(
trans = "log10",
limits = c(0.01, 500),
breaks = c(0.01, 0.1, 1, 10, 100, 500),
labels = c(0.01, 0.1, 1, 10, 100, 500)
) +
annotation_logticks(sides = "l") +
theme_bw()