- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我有一个分类 y 变量时,我想避免垂直重叠的 geom_point。
library(tidyverse)
# all possible points
df <- expand.grid(
y_factor = paste0('factor_',1:5),
x =1:100
)%>%as.tbl
# randomly missing and overlapping points
# every green point has a pink point underneath, and every blue point
# has a green point underneath it.
seed<-1
df_with_overlap<-df%>%
sample_frac(0.5,replace = TRUE)%>%
group_by(y_factor,x)%>%
mutate(n=factor(1:n()))
p<-ggplot(data=df_with_overlap, aes(x=x, y=y_factor, col=n))
p+geom_point()
使用 position_dodge
进行水平躲避不起作用,因为该轴上的数据太拥挤,因此某些点仍然重叠,并且可视化效果不清晰。
p+geom_point(position=position_dodge(width=1))+
ggtitle('position_dodge isnt what Im looking for.
\nx-axis too crowded and points still overlap')
position_jitter
是有效的,因为我可以将 x 抖动限制为 0,并控制 y 抖动程度。但抖动的随机性使其吸引力降低。当这 3 种颜色存在时,我可以辨认出它们。
p+geom_point(aes(col=n), position=position_jitter(width=0, height=0.05))+
ggtitle('Jitter kind of works.
\nIt would work better if it wasnt random
\nlike position_dodge, but vertical dodging')
有没有办法垂直躲避点?
最佳答案
感谢@aosmith建议ggstance::position_dodgev()
。这正是我一直在寻找的。我增加了过采样,所以效果更明显。
df <- expand.grid(
y_factor = paste0('factor_',1:5),
x =1:100
)%>%as.tbl
seed<-1
df_with_overlap<-df%>%
sample_frac(1.5,replace = TRUE)%>%
group_by(y_factor,x)%>%
mutate(n=factor(1:n()))
ggplot(data=df_with_overlap, aes(x=x, y=y_factor, col=n))+
geom_point(position=ggstance::position_dodgev(height=0.3))
关于r - geom_point 在分类尺度上的position_dodge 的垂直等效值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52338137/
The documentation没有解释这究竟是什么width争论 它指定了谁的宽度? 什么是“单位”? 默认值是多少? 默认值为 width = NULL ,但反复试验表明 width = 0.9
对于两个分类变量的每个交叉分类,我有五个数据点。我试图在误差线之间添加一些均匀的间距,这样它们就不会在多面 ggplot2 图中重叠,但失败了。数据很像这样...... library(ggplot2
我正在尝试使用 ggplot2 函数 geom_text 在条形图上方添加标签(字母)。我的条形图使用 position=position_dodge() 分隔,因此我需要对新标签应用相同的条形图。不
我正在尝试使用 ggplot2 函数 geom_text 在条形图上方添加标签(字母)。我的条形图使用 position=position_dodge() 分隔,因此我需要对新标签应用相同的条形图。不
我的问题与这个 question 密切相关,但是是一个后续问题,而不是重复。我的绘图问题与将 postion_dodge() 与 geom_line() 一起使用有关。 数据: Behaviour R
我正在尝试在 R 中生成一个双因子实验图。它包含三个级别,每个级别都有两个子级别。我想对这些组中的每一个进行注释,但我找不到合理的方法。 这是一个为顶级生成注释的示例: ggplot(mtcars,
问题:我的数据集有一个共享基线(时间点 1)和 2 个重复测量。后续点在 2 个不同的条件下重复(即交叉)。绘图时,结果、误差线和数据点重叠。 library(tidyverse) set.seed(
我在使用 ggplot2 时遇到了以下困难。我正在尝试创建一个带有时间序列数据集的条形图,其中显示每个条形的值和 x 轴下的一个不错的日期格式。问题是: 要设置在柱内或柱上方,必须使用 positio
我看到了 this回答但无法复制。 我得到这样的数据: df = data.frame(x = rep(sample(letters, 4), 2), y = roun
我正在尝试使用 ggplot、geom_poitrange 绘制图形。我有两组,每组有两个点和相应的错误值。我使用的代码如下: group<-c("A","A","B","B") va
我试图在 geom_boxplot 中标记异常值使用 ggrepel::geom_label_repel .当只有一个分组变量时它工作得很好,但是当我尝试将它用于多个分组变量时,我遇到了问题。由于某种
我正在尝试用 geom_text 标记条形图。它在大多数情况下适用于 position_dodge,但在某些情况下,我得到的图看起来像这样。我使用 preserve = 'single' 绕过宽条,但
我想做的是同时使用 position = "fill"和 position = "dodge" geom_bar() 的参数同时不知何故。使用一些样本数据 set.seed(1234) df %
使用下面的代码,刻面 bB 中的标签未正确定位。 问题似乎源于没有position_dodge(preserve="single")为 geom_text (正确的?)。我知道我可以“手动”添加一个空
我想在其中一个闪避条上专门放置一些东西,我该怎么做? 在下面的示例中,我想在条形图的 cat3 组中的 A3 上专门放置一些东西。我知道 cat3 的 x = 3 但由于闪避宽度和条宽的相互依赖性,似
我是一名优秀的程序员,十分优秀!