- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想做的是:
a) 让 ggplot 代码每次运行时生成的图都相同 [set.seed 是一种概念吗?] 和
b) 仅对具有相同 y 轴值的标签进行抖动文本标签 - 保留其他文本标签。这似乎是某种基于点因子值的条件抖动。
这是一些数据:
dput(df)
structure(list(Firm = c("a verylongname", "b verylongname", "c verylongname",
"d verylongname", "e verylongname", "f verylongname", "g verylongname",
"h verylongname", "i verylongname", "j verylongname"), Sum = c(74,
77, 79, 82, 85, 85, 88, 90, 90, 92)), .Names = c("Firm", "Sum"
), row.names = c(NA, 10L), class = "data.frame")
这是使用 df 的 ggplot
代码:
ggplot(df, aes(x = reorder(Firm, Sum, mean), y = Sum)) +
geom_text(aes(label = Firm), size = 3, show.guides = FALSE, position = position_jitter(height = .9)) +
theme(axis.text.x = element_blank()) +
scale_x_discrete(expand = c(-1.1, 0)) + # to show the lower left name fully
labs(x = "", y = "", title = "")
请注意,该图的一个版本仍然与 h 和 i 重叠——每次运行上述代码时,文本标签的位置都会发生变化。
顺便说一句,这个问题conditional jitter稍微移动 x 轴上的离散值,但我想(仅)移动 y 轴上的重叠点。
最佳答案
一种选择是添加一列来标记重叠点,然后分别绘制它们。更好的选择可能是直接移动重叠点的 y 值,以便我们可以直接控制它们的位置。我在下面展示了这两个选项。
选项 1(抖动):首先,添加一列来标记重叠。在这种情况下,因为这些点几乎落在一条线上,所以如果它们的 y 值太接近,我们可以将任何点标记为重叠。如果检查 x 值是否接近也很重要,您可以包含更复杂的条件。
df$overlap = lapply(1:nrow(df), function(i) {
if(min(abs(df[i, "Sum"] - df$Sum[-i])) <= 1) "Overlap" else "Ignore"
})
在图中,我将抖动点涂成红色,这样很容易看出哪些点受到了影响。
# Add set.seed() here to make jitter reproducible
ggplot(df, aes(x = reorder(Firm, Sum, mean))) +
geom_text(data=df[df$overlap=="Overlap",],
aes(label = Firm, y = Sum), size = 3,
position = position_jitter(width=0, height = 1), colour="red") +
geom_text(data=df[df$overlap=="Ignore",],
aes(label = Firm, y = Sum), size = 3) +
theme(axis.text.x = element_blank()) +
scale_x_discrete(expand = c(-1.1, 0)) + # to show the lower left name fully
labs(x = "", y = "", title = "")
选项 2(直接放置):另一个选项是直接控制标签移动的量,而不是采用发生给我们的任何抖动
。在这种情况下,我们知道我们想要以相同的 y 值移动每对点。如果我们需要同时担心 x 和 y 值、同一重叠中的两个以上点,和/或我们需要移动接近但不完全相同的值,则需要更复杂的逻辑。
library(dplyr)
# Create a new column that shifts pairs of points with the same y-value by +/- 0.25
df = df %>% group_by(Sum) %>%
mutate(SumNoOverlap = if(n()>1) Sum + c(-0.25,0.25) else Sum)
ggplot(df, aes(x = reorder(Firm, Sum, mean), y = SumNoOverlap)) +
geom_text(aes(label = Firm), size = 3) +
theme(axis.text.x = element_blank()) +
scale_x_discrete(expand = c(-1.1, 0)) + # to show the lower left name fully
labs(x = "", y = "", title = "")
注意:要使抖动可重现,请在抖动绘图代码之前添加 set.seed(153)
(或任何您想要的种子值)。
关于r - 如何使用 "jitter"生成相同的图,以及如何抖动选定的点(不是所有点)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32527713/
我有一个导航栏,当您将鼠标悬停在导航按钮上时,我想给它一个橙色的底部边框。唯一的问题是,无论何时悬停,边框都会使内容/导航按钮“抖动”,这是它们不应该的。此外,我已经在导航栏上始终设置了黑色底部边框,
根据documentation ,jitter 函数的解释是“向数值向量添加少量噪声。” 这是什么意思? 是否有一个随机数与向量中的每个数字相关联并添加到其中? 最佳答案 抖动确实意味着只是将随机噪声
假设我有这样的东西: for (int i = 0; i > 1或 x << 1 . Does the jitter actually do so when it is legal? 我不知道。试试吧
我正在使用 Photos 框架和 requestImageForAsset: 花费太多时间,因此它的滚动性能确实很差。 我尝试将 PHImageRequestOptions 选项设置为: let op
我正在开发一个 View Controller 原型(prototype),该原型(prototype)由具有以下要求的 collectionView 组成: 有一张背景图片可见 部分可以像 Acco
我是 Java 的新手,我很好奇 Java 与 C++ 相比如何处理普通任务。因此,我将 2 个 C++ 字符串格式化方法(sprintf 和 ostringstream)与使用 Java 的 Str
我正在为我的VOIP应用程序寻找Java中的自适应 jitter buffer 实现。我为应用程序编写了一个固定的 jitter buffer ,但是由于网络质量差,我遇到了缓冲区不足或缓冲区溢出的问
我要绘制三个组的测量值,每个组有五个观察值。我想绘制所有点,但是每个组中的数值都非常接近。改变 alpha 有帮助,但仍然很难观察到单独的点。 因此我想添加一些水平扩展(在 X 轴上)。点的部分重叠是
我想做的是: a) 让 ggplot 代码每次运行时生成的图都相同 [set.seed 是一种概念吗?] 和 b) 仅对具有相同 y 轴值的标签进行抖动文本标签 - 保留其他文本标签。这似乎是某种基于
我要绘制三个组的测量值,每个组有五个观察值。我想绘制所有点,但是每个组中的数值都非常接近。改变 alpha 有帮助,但仍然很难观察到单独的点。 因此我想添加一些水平扩展(在 X 轴上)。点的部分重叠是
对于 VoIP 语音质量监控应用程序,我需要将传入的 RTP 音频流与引用信号进行比较。对于信号比较本身,我使用预先存在的专用工具。对于其他部分(抓包除外),Gstreamer 库似乎是一个不错的选择
使用 Bootstrap (3.3.6) 折叠,可折叠的 DIV 位于表单输入\标签之间。当 DIV 展开\隐藏时,会出现一种快速\抖动。 问题代码:https://jsfiddle.net/ybto
在我当前的代码库中,复杂的 if 语句通常被委托(delegate)调用所取代。由于代码的结构,在应用程序的过程中将多次调用同一个委托(delegate)。例如, class ExampleClass
我的一个应用程序中的 Gallery 小部件遇到了一个相当奇怪的问题,我想是时候问问其他人了,因为它已经困扰我很长时间了. 我正在为 Gallery 小部件使用自定义 Adapter,并且我在此为 G
我一直在阅读 Eric Lippert的 article关于 C# 编译器的/optimize 命令行选项。文章描述了编译器执行的优化类型。但是,我仍然不清楚此选项是否也会影响 JIT 优化。并非不可
我制作了以下图 block ,带有悬停效果,通过 CSS-transition 增加了 font-size: body { font-family: 'Segoe UI', sans-serif;
如果一个进程被硬件中断(第一级中断处理程序)中断,那么 CPU 调度程序是否意识到这一点(例如,调度程序是否独立于被中断的进程计算硬件中断的执行时间)? 更多详情:我正在尝试解决以下问题:htop 中
如何消除错误 jitter buffer full ? 我使用来自最新快照之一的 ffmpeg。 ffmpeg 版本 N-90078-gf611fef 版权所有 (c) 2000-2018 the F
附上一张照片来解释这个概念,但本质上,我想要一个背景视频或图像,上面有多个 png 像这样分层。 我将如何实现这一目标?我觉得 jit.alphablend 是这个的一个组成部分...... 我也在
我正在更新a package that uses base graphics至 one that uses ggplot2 graphics 。在基本图形版本中,用户可以为 jj 提供一个值,然后该值
我是一名优秀的程序员,十分优秀!