在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论