我是 R 新手。我会尽量简洁明了。目前,我正在尝试在单个离散 x 轴上基于另一个条件连接两个条件之间的点。
下面是一些测试数据和我尝试绘制的一些数据。
set.seed(42)
# Test case data
mydf1 <- tibble(
xx = rep('myLabel', 8),
yy = rnorm(8),
grp = rep(c(1, 2), each = 4),
cond = rep(c('a', 'b', 'c', 'd'), length.out = 8)
)
ggplot(mydf1, aes(x = xx, y = yy, col = factor(grp))) +
geom_point(position = position_dodge(width = 0.9)) +
geom_path(position = position_dodge(width = 0.9), aes(group = cond), col = "black") +
theme_bw() +
ggtitle("Test Case for geom_path and position_dodge")
据我所知,position_dodge 似乎是在抽签之后应用的。有办法改变这种行为吗?或者以这种方式实现连接这些点的总体目标?
感谢您的宝贵时间。
编辑:详细信息。
编辑2:
我想根据一个大的主要条件中的 4 个条件捕获 grp
之间的前后关系。
最佳答案
也许你想要这个。
set.seed(42)
library(ggplot2)
ggplot(mydf1, aes(x = grp, y = yy, col = factor(grp))) +
geom_point() +
geom_path(aes(group = cond), col = "black") +
theme_bw() +
ggtitle("Test Case for geom_path and position_dodge") +
xlim(c(.5, 2.5)) +
labs(color = "Group", x = "myLabel", y = "yy") +
theme(axis.text.x=element_blank(),
axis.ticks.x=element_blank())
关于r - 如何绘制带有躲避位置的图形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48894730/