【问题标题】:Increase distance between points in a categorical X axis增加分类 X 轴中点之间的距离
【发布时间】:2019-11-26 20:30:28
【问题描述】:

我将geom_pointposition_dodge 结合使用来绘制点并将它们在水平轴上稍微展开。问题是基准的点太接近另一个基准的点(即 atax 和 bicg)。

当轴是分类轴时,如何增加 X 轴刻度之间的距离?或者我如何防止不同基准的点相互接触。

下面是我用来在1上生成图形的代码

ggplot(data = df, aes(x = Benchmark, y = time, shape = type)) +
    theme_light() +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    scale_shape_manual(values = c(0, 1, 2, 3, 4)) +
    geom_point(position = position_dodge(width = 1), color = 'gray60', size = 2)

【问题讨论】:

    标签: r ggplot2 plot graphics


    【解决方案1】:

    您可以使用scale_x_discrete 中的expand 参数来执行此操作,在绘图中添加一条看起来像scale_x_discrete(expand=c(0.2, 0.2)) 的线并使用这些值。

    【讨论】:

    • 感谢您的帮助。我试过了,但结果看起来一点也不专业! imgur.com/4JP7ZPt 。理想情况下,我想将position="dodge"geom_point 一起使用,这将产生与使用geom_bar 相同的结果。
    • geom_jitter() 代替geom_point() 怎么样?那应该可以解决重叠问题,我认为这是主要问题吗?
    • geom_jitter() 的问题是我希望相同类型的点在水平轴上以相同的量抖动,但geom_jitter() 会将每个点移动随机量。顺便说一句,这是geom_jitter() 的结果:imgur.com/XQqBkfR