- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在尝试绘制每年朱利安日期的苍蝇密度。目的是查看两种数据收集方法(第 1 组和第 2 组)的苍蝇密度何时达到峰值。我有很多行数据,在10年的过程中,例如,数据集是这样的:
年
朱利安
团体
2000年
214
1
2001年
198
1
2001年
224
1
2000年
189
2
2000年
214
2
2001年
222
2
2001年
259
2
2000年
260
2
2000年
212
1
每一行都是一个观察值。
这是我第一次使用 ggplots 绘图,所以我对如何绘制每年的垂直峰值线感到困惑。
目前的代码如下所示:
代码
data$group <- as.factor(data$group)
plots <- ggplot(data, aes(x = julian, group = group)) +
geom_density(aes(colour = group),adjust = 2) + facet_wrap(~year, ncol = 2)
我尝试使用此代码绘制峰值:
geom_vline(data = vline, aes(xintercept = density(data$julian)$x[which.max(density(data$julian)$y)]))
vline <- summarise(group_by(data,year, group=group), density(ata$julian, group=group)$x[which.max(density(data$julian)$y)])
vline
但是我认为它已经找到了所有年份和所有组的峰值密度。
最佳答案
与其试图将所有计算都集中在一行代码中,我建议将其拆分为这样的步骤。我没有使用您的代码来查找最高峰,而是使用了 this原则上也应该找到多个峰值的答案(见下文):
library(dplyr)
library(ggplot2)
fun_peak <- function(x, adjust = 2) {
d <- density(x, adjust = adjust)
d$x[c(F, diff(diff(d$y) >= 0) < 0)]
}
vline <- data %>%
group_by(year, group) %>%
summarise(peak = fun_peak(julian))
#> `summarise()` has grouped output by 'year'. You can override using the `.groups` argument.
ggplot(data, aes(x = julian, group = group)) +
geom_density(aes(colour = group), adjust = 2) +
geom_vline(data = vline, aes(xintercept = peak)) +
facet_wrap(~year, ncol = 2)
x <- c(1,1,4,4,9)
data <- data.frame(
year = 2000,
julian = rep(c(1,1,4,4,9), 2),
group = rep(1:2, each = 5)
)
data$group <- as.factor(data$group)
vline <- data %>%
group_by(year, group) %>%
summarise(peak = fun_peak(julian, adjust = 1))
#> `summarise()` has grouped output by 'year', 'group'. You can override using the `.groups` argument.
ggplot(data, aes(x = julian, group = group)) +
geom_density(aes(colour = group), adjust = 1) +
geom_vline(data = vline, aes(xintercept = peak)) +
facet_wrap(~year, ncol = 2)
关于r - 在两个数据集的 facet wrapped ggplot 上查找多个峰值密度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68420556/
;) 如果您想将 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 将根据分辨率/密度元数据知道要打印的每英寸像素
我是一名优秀的程序员,十分优秀!