[R] Plot step function
Göran Broström
goran.brostrom at umu.se
Sat Feb 6 21:12:33 CET 2016
On 2016-02-06 19:23, David Winsemius wrote:
>
>> On Feb 6, 2016, at 4:11 AM, jupiter <jupiter.hce at gmail.com> wrote:
>>
>> Hi,
>>
>> I am just starting to learn R, sorry for asking a simple question. How can
>> plot a line x <= 0 y = 0, x > 0 y = 1?
>
> There is a stepfun function and an associated plotting method:
>
> y0 <- c(rep(0,3),rep(1,3))
> sfun0 <- stepfun(-2:2, y0, right=TRUE)
> plot(sfun0)
I would like to suggest the correct way:
Replace the last line by
> plot(sfun0, verticals = FALSE)
Göran Broström
More information about the R-help
mailing list