2
votes

I have a dataframe that looks like this:

   Month   value
1 2018-07 0.5241422
2 2018-08 0.6197477
3 2018-08 3.3603833
4 2018-10 0.5357588
5 2018-09 0.8397401

I would like to plot it to something similar to these graphs below; while the error bar range can actually show the max the min of "value" each Month:

or enter image description here

I won't need mean +/Ci, I will just need it to show the max and min value by month, and mean in the middle also (not necessary)

I've tried to duplicated a few solutions from Scatter plot with error bars

However, the main problem is that I cannot make the min and max value specific to each month, instead, it will show the actual max & min value of the whole data frame.

A similar result to what I need is this...


df %>% 
  ggplot(aes(x = Month, y = value)) +
  geom_boxplot(alpha = 0.4) +
  theme_minimal() +
  expand_limits(y = 0) +
  labs(y =  "") 

It would be very appreciated for some help. Thanks!

1
Hey are you looking for something like this ? stackoverflow.com/questions/29375169/…ealbsho93

1 Answers

3
votes

I see you updated your question and I modified my answer accordingly. You can calculate the min,max and mean first and then used calculated data to create the plot. Is this what you want?

library(tidyverse)
library(lubridate)

data <- tibble(
    date = rep(seq(ymd("2019-01-01"),ymd("2019-12-01"),by = "1 month"),10),
    value = 1 +runif(120)
) %>%
    arrange(date)

data_range <- data %>%
    group_by(date) %>%
    summarise(max = max(value),
              min = min(value),
              mean = mean(value))

data_range %>%
    ggplot(aes(x = date,y = mean)) +
    geom_line() +
    geom_point() +
    geom_errorbar(aes(ymin = min, ymax = max))


enter image description here