With data like below, that plots the CDF of two different columns in the data frame, need to add some part of the summary stats to the plot.
To plot the CDF I do the following
set.seed(1234)
df <- data.frame(height1 = round(rnorm(200, mean=60, sd=15)), height2 = round(rnorm(200, mean=55, sd=10)))
df %>% pivot_longer(c('height1', 'height2'), names_to = "Group", values_to = "value") %>%
ggplot(aes(value, colour = Group)) +
stat_ecdf()
The above gives the CDF
I need to add some summary stats to this plot and need help with getting the following 2 representations.
The summary stats table is generated as
tbl = df %>% pivot_longer(c('height1', 'height2'), names_to = "Group", values_to = "value") %>%
group_by(Group) %>%
summarize(Samples = n(), Median=median(value, na.rm=T), Pctl_10th=quantile(value, 0.1, na.rm=T))
One thing with Samples
is that it should omit NA
s.
- CDF with Summary Stats inside the plot positioned at the bottom left corner
- CDF with Summary Stats outside the plot positioned at the bottom left corner
Looking for an answer that covers the following
- Using ggpmisc ,
tableGrob
packages or other mainline package - Flexibility in specifying the position of the table relative to bottom-right or bottom-left or top-right or top-left corners of the graph or the whole plot area ( as in the second example).