Quantcast
Channel: Adding "months" as x-axis labels to a plot - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Adding "months" as x-axis labels to a plot

$
0
0

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.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images