Skip to content

Available in S-plus, also in R1.8.1?

2 messages · Hoeven, Maarten van der, Uwe Ligges

#
Agree, if a plot needs to be explained, something is not very well
thought of. However, there are good rationals to do it this way.
Moreover, I'm using R to replace SPSS-functionality (and imaging by
pvwave) within a project, and I want to be close as possible to the
image output of the preceeding project. Hence, this question.

The assumption is indeed an equidistant x-axis. This is true in my case.

What the stairstep-plot in R does (type="s" or type="S"), is to draw a
horizontal line between two points on the x-axis. For example,

x1 = 1980
x2 = 1981
x3 = 1982
y1 = 10
y2 = 12
y3 = 14

it draws a horizontal line between 1980 and 1981, at y-level 10 (or 12,
depening on type="s" or type="S").

What I'm looking for, and this can be achieved in S+ by the mentioned
connect type, is that the horizontal line *NOT* starts at exactly the
x-values, but half between. See the attached example, where there is
only one y-value of 1, at x=1995. You see the plot been drawn halfway
1995 (half before 1995, and half after 1995). This is what I'm look ing
for. When using type="s" and type="S" in the plot-function, this would
result in a polot that starts exactly at 1995, or ends exactly at 1995.
I want to have it in between.

Thanks,

Maarten
--------------------------------------------------------------
Zie ook/see also: http://www.knmi.nl/maildisclaimer.html
#
Hoeven, Maarten van der wrote:

            
Now that I (hopefully) understand what you are going to do, the solution 
seems to be simple:

  x <- 1980:1982
  y <- c(10, 12, 14)

  n <- length(x)
  xdiff2 <- diff(x[1:2])/2
  x2 <- c(x - xdiff2, x[n] + xdiff2)
  y2 <- c(y, y[n])
  plot(x2, y2, type="s")


Uwe Ligges