I need help plotting month names on the x axis, instead of the level the months are assigned. I am working with a "water year", so October is assigned to be level 1, and ending with September being level 12. I'm sure this is easy, I just don't often work with factors. Thanks!
Research Done: Plot a character vector against a numeric vector in R
Here is a simplified example of my data
Months<-c("Jan"=4,"Feb"=5,"Mar"=6,"Apr"=7,"May"=8,"Jun"=9,"Jul"=10,
"Aug"=11,"Sep"=12,"Oct"=1,"Nov"=2,"Dec"=3)
Data<-c(1,2,3,4,5,6,7,8,9,10,11,12)
df<-data.frame(Months,Data)
>df
Months Data
Jan 4 1
Feb 5 2
Mar 6 3
Apr 7 4
May 8 5
Jun 9 6
Jul 10 7
Aug 11 8
Sep 12 9
Oct 1 10
Nov 2 11
Dec 3 12
plot(Data~factor(Months), df,las=2)
This puts the data in the correct place with the correct month, just the wrong labels.
We can use
xaxt = "n"
inplot
and then withaxis
change thexaxis
tick labelsUse argument to
plot
xaxt = "n"
and then functionaxis
.