在ggplot2中,我可以调整坐标由因子水平确定的点和线吗?

发布于 2024-12-04 07:16:38 字数 1232 浏览 0 评论 0原文

可能的重复:
ggplot2 条形图中的订单条形
R:ggplot2偏移散点图点

我有一个示例 data.frame 并在此处绘制。我想稍微重新定位“工厂”类型内的点和水平误差线,以便它们不会彼此重叠。

## example data.frame 
df <- structure(list(factory = structure(c(1L, 1L, 4L, 4L, 3L, 3L, 
2L, 2L), .Label = c("A", "B", "C", "D"), class = "factor"), response = c(0.12, 
0.08, 0.14, 0.11, 0.12, 0.11, 0.15, 0.09), lci = c(0.13, 0.1, 
0.11, 0.09, 0.11, 0.06, 0.13, 0.06), uci = c(0.14, 0.07, 0.15, 
0.1, 0.22, 0.14, 0.15, 0.08), variable = structure(c(1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L), .Label = c("T1", "T2"), class = "factor")), .Names = c("factory", 
"response", "lci", "uci", "variable"), row.names = c("3", "4", 
"5", "6", "7", "8", "9", "10"), class = "data.frame")

## example plot
qplot(response, factory, colour = variable, data = df) +
  geom_point() +
  geom_errorbarh(aes(xmax = response + uci, xmin = response - lci),
                 height = .25)

如果您查看示例图,我想您会明白我的意思。有人知道怎么做吗? position_dodge 看起来很有希望,但我不知道如何使其与点和错误栏一起使用。

Possible Duplicate:
Order Bars in ggplot2 bar graph
R: ggplot2 offset scatterplot points

I have an example data.frame and plot here. I would like to slightly re-position the points and horizontal errorbar lines within 'factory' type, so that they don't overlap with each other.

## example data.frame 
df <- structure(list(factory = structure(c(1L, 1L, 4L, 4L, 3L, 3L, 
2L, 2L), .Label = c("A", "B", "C", "D"), class = "factor"), response = c(0.12, 
0.08, 0.14, 0.11, 0.12, 0.11, 0.15, 0.09), lci = c(0.13, 0.1, 
0.11, 0.09, 0.11, 0.06, 0.13, 0.06), uci = c(0.14, 0.07, 0.15, 
0.1, 0.22, 0.14, 0.15, 0.08), variable = structure(c(1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L), .Label = c("T1", "T2"), class = "factor")), .Names = c("factory", 
"response", "lci", "uci", "variable"), row.names = c("3", "4", 
"5", "6", "7", "8", "9", "10"), class = "data.frame")

## example plot
qplot(response, factory, colour = variable, data = df) +
  geom_point() +
  geom_errorbarh(aes(xmax = response + uci, xmin = response - lci),
                 height = .25)

If you look at the sample plot, I think you'll see what I'm after. Anyone know how? position_dodge seems promising, but I couldn't see how to make it work with points and errorbars.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文