开发者

Extending the line to the end while plotting?

开发者 https://www.devze.com 2023-04-09 17:22 出处:网络
In reference to this开发者_开发知识库 question here, I managed to plot an ECDF for my data. However, I was wondering if it is possible to extend the lines to the extreme left/right of the graph much l

In reference to this开发者_开发知识库 question here, I managed to plot an ECDF for my data. However, I was wondering if it is possible to extend the lines to the extreme left/right of the graph much like how base R plots it? Any suggestions?

Extending the line to the end while plotting?

I want the lines to look more like this (extending to the extreme left/right of the graph and not ending abruptly as above):

Extending the line to the end while plotting?


Probably, at the moment, there is no way to do automatically. You can set the range of drawing by adding manually limits to data frame.

# sample data frame
df <- data.frame(x = c(rnorm(100, -3), rnorm(100), rnorm(100, 3)), g = gl(3, 100))
df <- ddply(df, .(g), summarize, x = x, y = ecdf(x)(x))

# add x min/max for each levels
df2 <- rbind(df, ddply(df, .(g), function(x) data.frame(x = range(df$x), y = c(0, 1))))

ggplot(df2, aes(x, y, colour = g)) + geom_line()

Extending the line to the end while plotting?


If you need to ensure that the function is monotonic, you can use something like:

    monotonic.y <- y;
    n <- length(monotonic.y);
    for (i in 1:n) {
       monotonic.y[i] <- max(monotonic.y[1:i]);
    }

and plot monotonic.y instead of y.

0

精彩评论

暂无评论...
验证码 换一张
取 消