I am plotting a curve using ggplot. I have the data which I calculated mean and se and stored in data. Then I used ggplot to plot the curve. So far everything looks good. But, I would like to scatter all three replicate data points for each time point and dose over their respective mean error bar. Can anyone help with my query. Here is my code:
structure(list(values = c(5L, 3L, 2L, 6L, 4L, 1L, 5L, 3L, 1L,
25L, 15L, 10L, 30L, 17L, 9L, 27L, 14L, 8L, 75L, 45L, 20L, 80L,
50L, 25L, 90L, 50L, 30L, 150L, 100L, 50L, 160L, 110L, 60L, 170L,
120L, 70L), dose = structure(c(3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L,
1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L,
3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L), .Label = c("2.5",
"5", "10"), class = "factor"), time = c(0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L)), row.names = c(NA, -36L), class = "data.frame")
my_data$dose <- as.factor(my_data$dose)
head(my_data)
library(dplyr)
data <- group_by(my_data, dose, time) %>%
summarise(
count = n(),
mean = mean(values, na.rm = TRUE),
sd = sd(values, na.rm = TRUE),
se = sd / sqrt(n())
)
data
p <- ggplot(data, aes(x=time, y=mean, group=dose)) +
geom_point(size = 1)+
geom_smooth(aes(linetype=dose), color = "black", se = F, size = 0.5)+
geom_errorbar(aes(ymin=mean - se, ymax=mean + se), width=1.8) +
labs(x ="sec", y = "Units") +
scale_x_continuous(breaks = seq(0, 35, 5), limits = c(-1, 35), expand = c(0, 0))+
scale_y_continuous(breaks = seq(0, 200, 20), limits = c(-10, 200), expand = c(0, 0))+
scale_linetype_manual(values=c( "dashed", "dotted", "solid"),
labels = c("2.5", "5", "10"))
p