ggplot2 - Extend x-limits using ggplot in R -



ggplot2 - Extend x-limits using ggplot in R -

i'm trying plot histogram overlay (given my_fun) using next code.

dfr = data.frame(x) ggplot(dfr,aes(x)) + geom_histogram(colour="darkblue", binwidth = 0.1, aes(y =..density..), size=1, fill="blue", freq = true)+ stat_function(fun = my_fun, colour = "red")

the x-axis in ggplot 1 2 (which range of data). however, plot have x-axis 0 3, overlay can drawn on range (0, 3).

i've tried adding coord_cartesian(xlim=c(0, 3)) not work. please provide me suggestions on changing range? give thanks you.

just guessing here since provided little useful info in question, works me:

dat <- data.frame(x=rnorm(100)) ggplot(dat,aes(x=x)) + geom_histogram(aes(y=..density..),freq=true) + stat_function(fun = dnorm, colour="red") + xlim(c(-4,4))

using xlim rather coord_cartesian. since haven't provided details on info or function, can't assure work in case.

r ggplot2

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -