【问题标题】:left/right bottom/top justification of tiles in ggplot2ggplot2中瓷砖的左/右下/上对齐
【发布时间】:2013-06-17 14:56:59
【问题描述】:

使用 ggplot2 geom_tile,瓦片的默认位置以 x 和 y 值为中心。有没有办法让 x 和 y 值成为每个图块的左下角。

来自http://docs.ggplot2.org/current/geom_tile.html

x.cell.boundary <- c(0, 4, 6, 8, 10, 14)
example <- data.frame(
  x = rep(c(2, 5, 7, 9, 12), 2),
  y = factor(rep(c(1,2), each=5)),
  z = rep(1:5, each=2),
  w = rep(diff(x.cell.boundary), 2)
)

qplot(x, y, fill=z, data=example, geom="tile")

【问题讨论】:

  • This 是一个密切相关的帖子。希望对您有所帮助。

标签: r plot ggplot2


【解决方案1】:

我不喜欢我的答案,但无论如何我都会在等待更好的解决方案时发布它。我转换数据(x 轴 +1 和 y 轴 +0.5)并将真实数据用作轴中断。

example <- data.frame( x = rep(c(3, 6, 8, 10, 13), 2), y = (rep(c(1.5,2.5), each=5)), z = rep(1:5, each=2))


ggplot(example)+ geom_tile(aes(x,y,fill=z)) +
scale_x_continuous(breaks=c(2, 5, 7, 9, 12))+
scale_y_continuous(breaks=c(1,2))

【讨论】:

  • 这实际上是我最终做的。
猜你喜欢
  • 2014-02-04
  • 2020-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-13
  • 2019-11-27
  • 2020-08-19
相关资源
最近更新 更多