r - How can you limit range of stat_function plots with ggplot2? -



r - How can you limit range of stat_function plots with ggplot2? -

i trying create figure show different saturation levels , effect on sampling dynamics talk using next code:

max <- 2 decay <- function(x, k, c) { c * (1 - exp(-k*x)) } require("ggplot2") ggplot(null, aes(x=x, colour = c)) + stat_function(data = data.frame(x = 0:max, c = factor(1)), fun = function(x) { decay(x, k=10, c=1e1) }) + stat_function(data = data.frame(x = 0:max, c = factor(2)), fun = function(x) { decay(x, k=10, c=1e2) }) + stat_function(data = data.frame(x = 0:max, c = factor(3)), fun = function(x) { decay(x, k=10, c=1e3) }) + stat_function(data = data.frame(x = 0:max, c = factor(4)), fun = function(x) { decay(x, k=10, c=1e4) }) + stat_function(data = data.frame(x = 0:max, c = factor(5)), fun = function(x) { decay(x, k=10, c=1e5) }) + stat_function(data = data.frame(x = 0:max, c = factor(6)), fun = function(x) { decay(x, k=10, c=1e6) }) + scale_colour_manual(values = c("red", "orange", "yellow", "green", "blue", "violet"), labels = c(1, 2, 3, 4, 5, 6)) + scale_colour_discrete(name=expression(paste(c, " value"))) + ylab(label="count") + ylim(0, 100)

the intention show high c value cases curve appear linear. however, ylim prevents curve beingness shown has value greater max ylim when expect simply truncate curve @ max value.

how desired behaviou?

you have noticed difference between limiting scale(using scale_y_continuous(limits=...)) or limiting coordinate space (using coord_cartesian(ylim=...).

when phone call ylim uses equivalent of scale_y_continuous , drops observations not in range

the help ylim , xlim describe (and point coord_cartesian alternative)

# here illustration rewritten ggplot(data = null, aes(x=x,colour=c)) + lapply(1:6, function(y){ stat_function(data = data.frame(x=0:max,c=factor(y)), fun = function(x) decay(x,k=10, c = 10^y))) + scale_colour_manual(values = c("red", "orange", "yellow", "green", "blue", "violet"), labels = c(1, 2, 3, 4, 5, 6)) + scale_colour_discrete(name=expression(paste(c, " value"))) + ylab(label="count") + coord_cartesian(ylim = c(0,100))

r ggplot2

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -