0

I have tried ribbon plot in R,but my output is not correct ,Can anyone tell whats the problem with my code,thanks in advance Output for ribbon plot

library(tidyr)
library(ggplot2)
library(dplyr)
library(reshape2)
library(tidyverse)
data = read.csv("Kolkata1.csv")
Dates = as.Date(data$X0)
data %>%  
select(X0, Rain1,Rain2) %>%
filter(as.Date("2001-01-01") > as.Date(X0)) %>% 
pivot_longer(!X0) %>%
group_by(X0) %>%
summarise(mean = mean(value, na.rm = T), sd = sd(value, na.rm= T),
high = mean(value, na.rm = T) + 0.2 * sd(value, na.rm= T),
low  = mean(value, na.rm = T) - 0.2 * sd(value, na.rm= T)) %>%
ggplot() +
geom_point(aes(as.Date(X0), mean), size = 3) +
geom_line(aes(as.Date(X0), mean), size = 1.1) +
geom_ribbon(aes(x = as.Date(X0), ymax = high, ymin = low),fill = "steelblue2", alpha = 1)+
theme_bw()
  • 3
    Welcome to Stack Overflow! You need to provide a [minimal, reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of your data. Taking the [Tour](https://stackoverflow.com/tour) and reading [How to Ask](https://stackoverflow.com/help/how-to-ask) can be helpful as well. – M-- Mar 03 '23 at 16:23
  • If you want to create a sample data using your 'Kolkata1.csv' file, read the file and subset few rows. `sub_kol <- kolkata[1:10, ]` and then do `dput(sub_kol)` and provide the output in the question so that we can work with sample data – 89_Simple Mar 03 '23 at 16:59
  • Dates Rain1 Rain2 2000-06-01 0.0 0.0 2000-06-02 0.0 0.000915518 2000-06-03 0.010818571 0.054956574 2000-06-04 12.117377 21.044977 2000-06-05 8.627044 11.062859 2000-06-06 10.958633 6.822417 2000-06-07 0.71884006 0.54492664 2000-06-08 13.484469 11.522052 2000-06-09 1.8801045 0.0695598 2000-06-10 14.092169 11.4799595 2000-06-11 25.222025 20.209724 – Tanvi Birla Mar 04 '23 at 19:21
  • These are values from first 10 rows! – Tanvi Birla Mar 04 '23 at 19:22

0 Answers0