r - ggplot中的堆栈点

标签 r plot ggplot2

我正在使用 ggplot 制作点图使用下面的代码和数据生成以下图表。

ggplot(data=holder, aes(x=Coef, y=CoefShort, colour=factor(Name))) + geom_point() + labs(x="Value", y="Coefficient") + scale_colour_discrete("Model")

dotplot

它们是大量的过度绘制,我想在点之间创建一些垂直分隔。但它必须是系统的,即顺序总是红-绿-蓝。
geom_stack似乎只在 x 值相同时才有效,而在 y 值相同时无效。我尝试使用相反的轴(交换 x 和 y),做一个 position_dodge()然后做一个 coord_flip() .这仅适用于条形,如下所示。
ggplot(data=holder, aes(y=Coef, x=CoefShort, fill=factor(Name))) + geom_bar(position="dodge", aes(ymax=Coef)) + labs(y="Value", x="Coefficient") + scale_fill_discrete("Model") + coord_flip()

Vertically dodged bar chart

任何想法如何使用 geom_point() 实现堆叠?谢谢。

数据:
structure(list(Coef = c(-3875.46969970703, 7871.08213392282, 1120.33185255098, 1510.13540851347, 1439.07714113149, 1800.92398445336, -3760.05411752962, 8183.74295221482, 1126.98290537184, 1517.99524139857, 1442.73063836897, 1808.03721179571, -90.6507661872817, -71.7225864185226, -103.615416254984, -732.167583256825, -1075.67574987664, -1908.56266462926, -7362.80215630299, 8886.12888250011, 655.767448263926, 848.716877683527, 869.395903077767, 998.254438325812, -211.682481369473, -303.310032581644, -506.1995360406, -978.697664841985, -1440.30190190734, -2325.22236024601, 2625.94998656519, 3573.68798735398, 4217.82910198788, 4534.8789695778, 4967.19941000705, 5072.02764498623, 5419.64684461491), Name = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), CoefShort = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L), .Label = c("(Intercept)", "carat", "Good", "Very Good", "Premium", "Ideal", "E", "F", "G", "H", "I", "J", "SI2", "SI1", "VS2", "VS1", "VVS2", "VVS1", "IF" ), class = "factor")), .Names = c("Coef", "Name", "CoefShort" ), class = "data.frame", row.names = c(NA, -37L))

最佳答案

积分在 geom_point是零宽度,所以你需要设置闪避的宽度:

ggplot(data=holder, aes(y=Coef, x=CoefShort, colour=factor(Name))) + 
  geom_point(position=position_dodge(width = 0.8)) + 
  labs(y="Value", x="Coefficient", colour = "Model") + 
  coord_flip()

enter image description here

关于r - ggplot中的堆栈点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8018288/

相关文章:

matlab - 如何在 MATLAB 中预测和扩展作为一维向量获取的数据?

r - 从 R 中的数据表中提取唯一行

r - 如何保存中间对象?

r - 我有一个包含多个组的专栏。我希望每个组都有自己的专栏

r - 如何在 ggplot2 中旋转标签?

r - ggplot2 图表轴中的印度风格千位分隔符

r - plotly 否决 ggplot 2's scale_fill_manual' s 标签

r - 无法过滤数据框?

r - 在 R 中按天绘制时间间隔

math - 如何在 GNU Octave 中绘制 2 个平面