您不能使用rChart 明确地做到这一点,但对于任何统计分布以及通常对于您想要的任何功能,您都可以很容易地做到这一点。您可以对d/r/p/q-distribution 形式的每个统计分布使用完全相同的技术,例如?rnorm、?rbinom 等。但这甚至可以推广到您想要的任何 函数。我还包括一个通用函数的示例。
对于使用dnorm 和rnorm 的正态分布:
x <- rnorm(1000) #you need rnorm here to create 1000 standard normally distributed observations.
y <- eval(dnorm(x)) #evaluate the function using dnorm now to get probabilities.
#the use of eval() will be clear in the next example. Here you can even omit it if it confuses you.
df <- data.frame(x,y) #make df
#plot
rPlot(y ~ x, data=df, type='line' )
同样,对于二项分布,您可以使用dbinom 和rbinom 进行完全相同的操作。其他任何发行版都一样。
您还可以根据@Gregor 的评论使用x = seq(-6, 6, length = 1000) 之类的东西而不是rnorm 函数来创建自定义x 变量,然后使用dnorm 生成相应的概率。这种方式的好处是可以直接设置x轴的范围。例如:
a <- seq(-6,6,length=1000) #use -10,10 to reproduce your example
b <- dnorm(a)
df <- data.frame(a,b)
rPlot(b~a,data=df,type='line')
作为如何绘制任何函数的演示和概括
我们以函数log(1+x) 为例。在这里,您将看到绘制任何函数是多么容易:
x <- runif(1000,1,10) #1000 points are enough
y <- eval(log(1+x)) #easily evaluate the function for your x vector
#the previous was a very special case where you had 2 functions rnorm and dnorm
#instead of an x vector and an f(x) function like here
#this is very easy to generalize
df <- data.frame(x,y) #make df
#plot
rPlot(y ~ x, data=df, type='line' )
你可以用同样的方式使用任何你想要的功能!