我有12个点显示月平均值。我想以x
个月为基础进行勾选。我尝试使用以下代码。它会在x
轴上勾选12个刻度,但不会输入名称。我无法找到错误?
{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"))}
答案 0 :(得分:1)
您可以使用axis命令手动设置轴刻度。
plot(1:12, xaxt = "n")
axis(1, 1:12, month.abb)
答案 1 :(得分:1)
我们没有数据,但此代码会创建所有标签,而不仅仅是适合的标签。如果您要使用自己的标签,首先需要使用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)
答案 2 :(得分:0)
您能提供想要绘制的数据样本吗?
我认为你在轴函数的at参数上犯了一个错误。
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)