I'm trying to plot the attached data in R using ggplot.
link of the data
Here's my script:
library(ggplot2)
dat<-read.csv("dat.csv",header=TRUE,sep=",")
dat<-data.frame(dat)
dat$min<-dat$zam-sd(dat$zam)
dat$max<-dat$zam+sd(dat$zam)
ggplot(dat,aes(dd,zam))
+geom_ribbon(aes(ymin=min,ymax=max),fill="skyblue")
+geom_line(color="steelblue4",lwd=1)
+theme(panel.background=element_rect(fill="white"), axis.line=element_line(colour="black"), panel.border = element_rect(colour = "black", fill=NA, size=5))
Question:
I would like the xaxis to be in months (January to December). But the data is for a leap year. I tried this command by gave an error.
dat$date <- seq(as.Date("2012/1/1"), as.Date("2012/12/31"), "month")
Error:
Error in
$<-.data.frame(*tmp*, "date", value = c(15340, 15371, 15400, : replacement has 12 rows, data has 366
Can anyone suggest a simple method to do this.
This will get you to dates:
dat$date <- as.Date(strptime(paste("2012", dat$dd), format="%Y %j"))
Then ggplot something like:
ggplot(dat, aes(date, zam) +
geom_ribbon(aes(ymin = min, ymax = max),fill = "skyblue") +
geom_line(color = "steelblue4", lwd = 1) +
scale_x_date(date_labels = "%B", date_breaks = "1 month")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With