clair.crossupton at googlemail.com
2009-Sep-10 10:44 UTC
[R] Issue displaying DATES on a plot with two ordinates
Dear all,
I am having an issue with displaying the dates on a plot with two
ordinates (i.e. two differently scaled y-axes). Instead of dates
appearing on the x-axis I am instead seeing a string of numbers
(14460, 14465, 14470 and 14475).
example R code:
library(plotrix)
x.Left <- as.Date(c('2009-08-04', '2009-08-08',
'2009-08-11',
'2009-08-15', '2009-08-18'), format="%Y-%m-%d")
x.Right <- as.Date(c('2009-08-05', '2009-08-09',
'2009-08-12',
'2009-08-16', '2009-08-19'), format="%Y-%m-%d")
y.Left <- c(70.13, 75.1, 74.35, 78.9, 80.92)
y.Right <- c(35, 45, 50, 47, 53)
twoord.plot(x.Left, y.Left, x.Right, y.Right, xlab="Date",
ylab="Trend
1", rylab="Trend 2", lwd=2, lcol='blue')
Thanks in advance for any help,
C.C.
P.S. I am aware of the criticisms of these sort of graphs, but they
are pretty. Also, they seem to be used a lot in meetings i've attended
recently.
Windows Vista> sessionInfo()
R version 2.9.2 (2009-08-24)
i386-pc-mingw32
locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.
1252;LC_MONETARY=English_United Kingdom.
1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
base
other attached packages:
[1] plotrix_2.7
Hi Clair, Good one for pointing out that dates on the x-axis are messy (and for bringing my mistake in the coloring of the ordinates to my attention). Attached is a revised version of the function that will be in the next version of plotrix. Try this: twoord.plot(x.Left, y.Left, x.Right, y.Right, xlab="Date", ylab="Trend 1",rylab="Trend 2", lwd=2,lcol='blue', xtickpos=x.Right[c(1,4)],xticklab=format(x.Right[c(1,4)])) Jim -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: twoord.plot.R URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090911/2d19703f/attachment-0001.pl>