[R] replacing default axis labels on a plot - SOLUTION
Graves, Gregory
ggraves at sfwmd.gov
Fri May 15 16:19:37 CEST 2009
The original problem posed was:
On 14/05/2009 7:31 AM, Graves, Gregory wrote:
> I have 3 columns: flow, month, and monthname, where month is 1-12,
and
> monthname is name of month. I can't get the plot to replace the 1-12
> with monthname using ticks.lab. What am I doing wrong?
>
> plot(flow~factor(month),xlab="Month",ylab="Total Flow per Month",
> ylim=c(0,55000), ticks.lab="monthname")
Here is the solution to this:
# make a boxplot but suppress default labels on x axis with xaxt="n"
plot(flow~factor(month),xlab="Month",ylab="Total Flow per Month",
ylim=c(0,55000), xaxt="n") #NOTE xaxt
# create a vector containing month abbrevs with [[1]] suffix as follows
month.name<-list(c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec"))[[1]]
# place the 12 months on axis 1 (the x axis) as follows:
axis(1, at=1:12, labels=month.name)
Gregory A. Graves
Lead Scientist
REstoration COoordination and VERification (RECOVER)
Watershed Division
South Florida Water Management District
Phones: DESK: 561 / 682 - 2429
CELL: 561 / 719 - 8157
More information about the R-help
mailing list