Reputation: 11
I have 12 points showing monthly average. I want to ticks x
monthy basis. I tried with following code . it ticks 12 ticks on x
axis but don't put the names. I am not able to find mistakes ?
{monthly_average<-aggregate(
dat.xts$CLPTHV43_Avr.wind.speed.1.m.s..91.,
as.yearmon(index(dat.xts)),
"mean",
na.rm=TRUE)
plot(monthly_average,
pch=20,
ylim=c(0,11),
type="o",
main="Average Monthly Wind Spped",
xlab="Months",
ylab="Wind Speed(m/s)")
axis(side = 1,
at=1:12,
lab=c( "July 2010",
"Aug 2010",
"Sep 2010",
"Oct 2010",
"Nov 2010",
"Dec 2010",
"Jan 2011",
"Feb 2011",
"Mar 2011",
"Apr 2011",
"May 2011",
"Jun 2011"))}
Upvotes: 1
Views: 282
Reputation: 263342
We don't have the data, but this code creates all the labels rather than just the labels that fit. If you are going to use your own labels you first need to suppress the default labeling with xaxt="n"
.
plot(1:12,1:12,
pch=20,
ylim=c(0,11),
type="o", xaxt="n",
main="Average Monthly Wind Spped",
xlab="Months",
ylab="Wind Speed(m/s)")
axis(side = 1,
at=1:12,
lab=c( "July 2010",
"Aug 2010",
"Sep 2010",
"Oct 2010",
"Nov 2010",
"Dec 2010",
"Jan 2011",
"Feb 2011",
"Mar 2011",
"Apr 2011",
"May 2011",
"Jun 2011"), las=3)
Upvotes: 1
Reputation: 121067
You can manually set axis ticks with the axis command.
plot(1:12, xaxt = "n")
axis(1, 1:12, month.abb)
Upvotes: 1
Reputation: 1586
Could you provide a sample of the data you want to plot?
I think you made a mistake at the at argument from the axis function.
library(zoo)
library(lattice)
monthly_average <- aggregate(dat.xts$CLPTHV43_Avr.wind.speed.1.m.s..91.,
as.yearmon(index(dat.xts)), mean, na.rm=TRUE)
plot(monthly_average, pch = 20, ylim = c(0, 11), type = "o",
main = "Average Monthly Wind Speed", xlab = "Months",
ylab = "Wind Speed(m/s)")
xlabel <- c("July 2010", "Aug 2010", "Sep 2010", "Oct 2010",
"Nov 2010","Dec 2010", "Jan 2011", "Feb 2011", "Mar 2011",
"Apr 2011", "May 2011", "Jun 2011")
axis(side = 1, at = monthly_average[, 1],
lab = xlabel)
Upvotes: 0