【发布时间】:2015-09-11 16:07:57
【问题描述】:
我想做的是:
a) 让ggplot 代码产生的情节在每次运行时都相同 [set.seed kind of notion?] 和
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 轴上的重叠点。
【问题讨论】:
-
如果你的主要目标是避免重叠,你可能喜欢这个问题stackoverflow.com/questions/30178954/…,这个问题在stats.SE上:stats.stackexchange.com/questions/16057/…