library(openxlsx)
library(ggplot2)
df <- read.xlsx("c:/users/fjcc/Documents/R/Play/Data.xlsx")
Mean <- mean(df$age)
SE_2 <- 2 * sd(df$age)/sqrt(nrow(df))
T_test <- t.test(df$age)
T_test
#>
#> One Sample t-test
#>
#> data: df$age
#> t = 369.33, df = 5533, p-value < 2.2e-16
#> alternative hypothesis: true mean is not equal to 0
#> 95 percent confidence interval:
#> 23.31577 23.56461
#> sample estimates:
#> mean of x
#> 23.44019
Conf_int <- T_test$conf.int
Plot_df <- data.frame(X = "age",
Avg = Mean,
SE_high = Mean + SE_2,
SE_low = Mean - SE_2,
Conf_int_high = Conf_int[2],
Conf_int_low = Conf_int[1])
#standard error
ggplot(Plot_df, aes(x = X, y = Avg, ymin = SE_low, ymax = SE_high)) +
geom_point() + geom_errorbar(width = 0.1) + labs(x = "", y = "mean and 2* SE") +
ylim(23.2, 23.6)

#Confidence Interval
ggplot(Plot_df, aes(x = X, y = Avg, ymin = Conf_int_low, ymax = Conf_int_high)) +
geom_point() + geom_errorbar(width = 0.1) +
labs(x = "", y = "mean and Conf Interval") +
ylim(23.2, 23.6)

#boxplot
ggplot(df, aes(x = "age", age)) + geom_boxplot(fill = "royalblue") +
labs(x = "", y = "")

Created on 2019-06-03 by the reprex package (v0.2.1)