4
$\begingroup$

I have some data in a CSV that pertains to bandwidth tests, like so:

Date.Time Mean Standard.Deviation
2025/12/24 12:06:46 88382 6046
2025/12/24 12:22:59 93813 3986
2025/12/24 13:36:06 91530 8136
2025/12/24 13:49:28 86613 12586
... ... ...
2026/02/26 09:56:33 53294 19979
2026/02/26 10:10:16 33435 16331

In RStudio, that data is in a frame with some other derived columns ("Day.of.Week", "Is.Business.Hours", etc.). I can filter on that data no problem.

The structure of the data frame is thus:

DATA2 %>% str
'data.frame':   6350 obs. of  13 variables:
 $ Test.Number       : int  1 2 3 ...
 $ Epoch             : int  1766596006 1766596979 1766598953 ...
 $ Date.Time         : chr  "2025/12/24 12:06:46" "2025/12/24 12:22:59" ...
 $ Date              : Date, format: "2025-12-24" "2025-12-24" "2025-12-24" ...
 $ Day.of.Week       : chr  "Wed" "Wed" "Wed" ...
 $ Time              : 'hms' num  12:06:46 12:22:59 12:55:53 ...
 $ Is.Business.Hours : logi  TRUE TRUE TRUE ...
 $ Max               : int  96460 95948 87756 ...
 $ Mean              : int  88382 93813 75173 ...
 $ Min               : int  74752 77312 55705 ...
 $ Standard.Deviation: int  6046 3986 9306 ...
 $ Std..Dev..Upper   : int  94428 97799 84479 ...
 $ Std..Dev..Lower   : int  82336 89827 65867 ...

I am using this to show a graph of every 50th test.

DATA2 %>% 
  filter( Test.Number %% 50 == 0 ) %>%
    ggplot2::ggplot() + 
    geom_col(aes(x = Date.Time, y = Mean, fill = Is.Business.Hours)) + 
    theme(axis.text.x = element_text(angle = -90, vjust = 0.5, hjust=1))

However, I'm not sure how to get "Mean" and "Standard.Deviation" into the chart. y = c(Mean, Standard.Deviation) doesn't seem to be a valid option within the aesthetic.

I would like to have the "Standard Deviation" value stacked on top of the "Mean" columns, where "stacked" means in the Z-axis (normal to the monitor), not a sum in the Y-axis. I did the below in LibreOffice as an example.

How would I replicate this same view in R/RStudio?

Image of Transfer speed and Standard Deviation.

$\endgroup$

1 Answer 1

3
$\begingroup$

This is a bit tricky - not because of the plot, but mostly because of how you would like to show the insight. SD and MEAN are inherently a bit difficult to portray in this manner.

To replicate what you had asked for, we can do something like this?

library(tidyverse)
set.seed(32)
n <- 20

DATA2 <- data.frame(
  Test.Number = 1:n * 50,
  Date.Time = format(seq(as.POSIXct("2025/12/24 12:00:00"), by = "1 hour", length.out = n), "%Y/%m/%d %H:%M:%S"),
  Mean = sample(33000:95000, n),
  Standard.Deviation = sample(3000:20000, n)
)

DATA2 %>%
  filter(Test.Number %% 50 == 0) %>%
  ggplot(aes(x = Date.Time)) +
  geom_col(aes(y = Mean), fill = "steelblue", width = 0.8) +
  geom_col(aes(y = Standard.Deviation), fill = "red", width = 0.5) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))

Mean and SD

But if we want to be more precise analytically, we can use a confidence interval. This essentially highlights the mean & 1 SD ranges.

DATA2 %>%
  filter(Test.Number %% 50 == 0) %>%
  ggplot(aes(x = Date.Time)) +
  geom_col(aes(y = Mean), fill = "steelblue", width = 0.8) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  geom_errorbar(aes(ymin = Mean - Standard.Deviation, ymax = Mean + Standard.Deviation), 
                width = 0.3, color = "red")

Mean & CI

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.