- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用以下方法绘制一些分布:
geom_density(aes(my.variable,
color=my.factor,
group=my.replicates,
y=..count..))
考虑到我在 my.factor 的每个级别中没有相同数量的重复,我想绘制重复的平均线(my.factor 的每个级别一条线)--> 我不能只删除“group”参数,因为 ..count.. 取决于重复次数。因此我想要类似 ..count../重复次数
我在 2 个栖息地(a 和 b)进行了采样:每个鱼的数量和体型。我在栖息地之间进行了不同的采样工作。 (ra 和 rb 分别是在栖息地 a 和 b 内采样的重复样本数)我对栖息地之间鱼类丰度和体型的平均差异感兴趣。但是,我不知道如何处理我没有相同数量的副本这一事实。
数据
#number of replicat
ra=4;rb=6
#number of individuals (lambda of poisson distribution)
na=30;nb=60
#size of individuals (lambda of poisson distribution)
sa=90;sb=80
#data for habitat a
dfa=data.frame()
for (ri in 1:ra){
habitat="a"
nb_rep=ra
replicat=paste("r",ri,sep="")
size=rpois(rpois(1,na),sa)
dfa=rbind.data.frame(dfa,data.frame(habitat,nb_rep,replicat,size))
}
#data for habitat b
dfb=data.frame()
for (ri in 1:rb){
habitat="b"
nb_rep=rb
replicat=paste("r",ri,sep="")
size=rpois(rpois(1,nb),sb)
dfb=rbind.data.frame(dfb,data.frame(habitat,nb_rep,replicat,size))
}
#whole data set
df=rbind(dfa,dfb)
绘图
require(ggplot2)
summary(df)
ggplot(df,aes(size,color=habitat))+
geom_density(aes(y=..density..))
ggplot(df,aes(size,color=habitat))+
geom_density(aes(y=..count..))
但是,如果没有付出同样的努力对栖息地进行采样,那么这是有偏差的即不同数量的重复
ggplot(df,aes(size,color=habitat,group=paste(habitat,replicat)))+
geom_density(aes(y=..count..))
从最后一个图中,如何获得重复的平均线?谢谢
最佳答案
我认为你不能在ggplot
中做到这一点。您可以自己计算密度,然后绘制计算出的密度。下面我通过使用 ggplot(df,aes(size,color=habitat)) + geom_密度(aes(y=..count..)) 重现已有的绘图来展示它实际上是有效的。 .
require(plyr)
# calculate the density
res <- dlply(df, .(habitat), function(x) density(x$size))
dd <- ldply(res, function(z){
data.frame(size = z[["x"]],
count = z[["y"]]*z[["n"]])
})
# these two plots are essentially the same.
ggplot(dd, aes(size, count, color=habitat)) +
geom_line()
ggplot(df,aes(size,color=habitat))+
geom_density(aes(y=..count..))
现在进行稍微困难的任务,即平均不同重复的密度。
# calculate the density
res <- dlply(df, .(habitat), function(dat){
lst <- dlply(dat, .(replicat), function(x) density(x$size,
# specify to and from based on dat, not x.
from=min(dat$size),
to=max(dat$size)
))
data.frame(size=lst[[1]][["x"]],
#count=colMeans(laply(lst, function(a) a[["y"]]), na.rm=TRUE)*nrow(dat),
count=colMeans(laply(lst, function(a) a[["y"]]), na.rm=TRUE)*nrow(dat)/nlevels(droplevels(dat$replicat)),
habitat=dat$habitat[1])
})
dd <- rbindlist(res)
ggplot(dd, aes(size, count, color=habitat)) +
geom_line()
关于r - 对分组变量求平均 geom_密度(y=..count..),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22809562/
;) 如果您想将 2mb 数据编码到 2d 条码中,哪种 2 条码适合作为起点或推荐。 今天有很多不同类型的二维条码,Aztec 二维条码、maxicodes、Pdf417、Microsoft HCC
我想创建一个具有密度的 3d 图。 我使用函数 density 首先为特定的 x 值创建一个二维图,然后该函数创建密度并将它们放入 y 变量中。现在我有第二组 x 值并将其再次放入密度函数中,然后我得
我对 geom_density 的以下变体的含义感到困惑在ggplot中: 有人可以解释这四个电话之间的区别: geom_density(aes_string(x=myvar)) geom_densi
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
重要编辑:最初的问题是关于获取 double 和分数的密度。当我得到 double 而不是分数的答案时,我正在改变主题以结束这个问题。原问题的另一半是here 新问题 我想找出 2 个给定数字之间的
如何计算 AVD 的抽象 LCD 密度? 最佳答案 抽象 LCD 密度以每英寸点数为单位(参见 docs)。 wikipedia article on Pixel density有一个有用的部分解释了
我使用(在 Windows 下)以下命令 magick convert -units pixelsperinch file_in -density 600 file_out 设置 JPG 图像的 dp
手机分辨率基础知识(dpi,dip计算) 1.术语和概念 术语 说明 备注 screen size(屏幕尺寸)
我尝试创建具有两个以上组的 Highcharts 密度。我找到了一种手动添加它们的方法,但必须有更好的方法来处理组。 示例:我想创建一个类似于下面的 ggplot 图表的 highchart,而不是将
我们有以下代码 convert foo.pdf foo.tiff 这多年来一直运行良好,并且由此产生的 tiff 是一个合理的打印质量。 我们刚刚升级了 imagemagick,现在 tiff 的分辨
ggplot2 中的 stats_ 函数创建特殊变量,例如stat_bin2d 创建一个名为 ..count.. 的特殊变量。在哪里可以找到列出哪个 stat_ 函数返回哪些特殊变量的文档? 我查看了
考虑以下几行。 p <- ggplot(mpg, aes(x=factor(cyl), y=..count..)) p + geom_histogram() p + stat_summary(fu
我想模拟 Samsung Galaxy Mini。我将分辨率设置为 240x320,将 LCD 密度设置为 180。这是否正确? 最佳答案 是的,绝对正确.... 关于android - Galaxy
我们需要获取Android手机或Pad的屏幕的物理尺寸,以便于界面的设计或是其他功能的实现。下面就分享一下Android中常用的一些辅助方法: 获取屏幕高度:
我创建了一个直方图/密度图函数,我希望 y 轴是计数而不是密度,但在参数化其 binwidth 时遇到问题。 我正在使用基于 http://docs.ggplot2.org/current/geom_
我试过四处搜索,但没有任何运气。我开发了一些使用大量图像的应用程序(大小大多为 200*200 像素)。我想通过添加不同尺寸的图像来支持不同的屏幕尺寸,但由于这会增加 apk 的许多兆字节,我需要知道
我正在尝试生成一个较小的图形来可视化 Pandas 时间序列。然而,自动生成的 x-ticks 不适应新的大小并导致重叠的刻度。我想知道如何调整 x-ticks 的频率?例如。对于这个例子: figs
我正在使用 geom_density 制作一系列密度图从数据框中,并使用 facet_wrap 按条件显示它,如: ggplot(iris) + geom_density(aes(x=Sepal.Wi
我已经从 From this example 了解了 APK 拆分概念 我已经尝试在我的项目中实现它,但只有 Drawable 文件夹受到影响。我也想拆分 Mipmap 文件夹。 下面是我的 buil
我需要在 javascript 中更改 JPG/PNG 类型图像的分辨率/密度。我需要这样做的原因是我可以将图像发送到第三方 API,然后第三方 API 将根据分辨率/密度元数据知道要打印的每英寸像素
我是一名优秀的程序员,十分优秀!