Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 当我想要一个接近0的正态分布且y为百分比时,ggplot未正确缩放_R_Ggplot2_Plot - Fatal编程技术网

R 当我想要一个接近0的正态分布且y为百分比时,ggplot未正确缩放

R 当我想要一个接近0的正态分布且y为百分比时,ggplot未正确缩放,r,ggplot2,plot,R,Ggplot2,Plot,这是一个可重复的例子 a <- data.frame(rnorm(1000,0,1)) colnames(a) <- c("test") ggplot(a,aes(test)) + geom_histogram(aes(y=(..count..)/sum(..count..))) + scale_y_continuous(labels=scales::percent) + stat_function(fun='dnorm') 我不知道你的问题是什么?你

这是一个可重复的例子

a <- data.frame(rnorm(1000,0,1))
colnames(a) <- c("test")

ggplot(a,aes(test)) +
    geom_histogram(aes(y=(..count..)/sum(..count..))) +  
    scale_y_continuous(labels=scales::percent) +
    stat_function(fun='dnorm')

我不知道你的问题是什么?你能贴一张你的情节的照片吗?你希望看到什么?柱状图有箱子,列的高度加起来应该是1.0;密度函数为概率函数,其总面积应为1.0;尝试在
geom_直方图
中的
binwidth
的值越低,您会看到直方图越高或越低,由于每个列的高度估计了任何所选数字出现在该特定存储箱中的概率。您可能还希望使用
set.seed
设置种子,因此
rnorm
中的数据是完全可复制的。