【问题标题】:How do I add another plot to hexbinplot?如何向 hexbinplot 添加另一个图?
【发布时间】:2016-08-08 19:32:13
【问题描述】:

我正在尝试在另一个地块上绘制焚化炉的位置。

# The first plot
hexbinplot(Easting~Northing | Bclass4, 
    BIRTH_NO68, las=1, scales =list(x = list(log = 10, equispaced.log = FALSE)), 
    aspect = 1, bins=50, style="nested.lattice", 
    main="Spatial distribution of birthweights by quartile")
# The second plot
ppp=xyplot(173098~319444, data=BIRTH_NO68, pch=17, cex=15, col="Black")
# Together
hexbinplot(Easting~Northing | Bclass4, BIRTH_NO68, las=1, 
    scales = list(x = list(log = 10, equispaced.log = FALSE)), aspect = 1, 
    bins=50, style="nested.lattice", 
    main="Spatial distribution of birthweights by quartile") + pop

出现的只是第一个情节。这是map I'm trying to mark the location of an incinerator on

【问题讨论】:

  • 我不知道是否因为需要在所有 4 个地块上显示焚化炉位置而变得更加困难?
  • 请列出您用于hexbinplot 功能的包。它不是基本 R 的一部分。R 有两个创建图形的过程:基本图形和网格。如果您使用的包使用基本图形,则在您的第一个图形上方添加par(mfrow=c(1, 2)) 以获得单行两列图形面板,或par(mfrow=c(2, 1)) 获得两行单列面板。请参阅?par 了解您可以调整的许多图形参数。对于grid 数字,它涉及更多。
  • 包是hexbin,有帮助吗?
  • 看CRAN上的包说明,hexbin是基于lattice包,使用grid图形引擎。 cran.mirrors.hoobly.com/web/packages/hexbin/index.html 在这种情况下,请在加载网格后查看?grid.layout。在 SO 上可能存在关于此功能的问题。

标签: r graphics lattice trellis


【解决方案1】:

看看 latticeExtra 中的as.layer,它可以让您轻松组合单个 lattice 图。以下是基于?hexbinplot 中提供的第一个示例的一些示例代码。

library(hexbin)
library(latticeExtra)

## example taken from ?hexbinplot
mixdata <- data.frame(x = c(rnorm(5000),rnorm(5000,4,1.5)),
                      y = c(rnorm(5000),rnorm(5000,2,3)),
                      a = gl(2, 5000))

p1 <- hexbinplot(y ~ x, mixdata, aspect = 1,
                 trans = sqrt, inv = function(x) x^2)

## add points plot to existing hexbinplot
p2 <- xyplot(2.5 ~ 3.5, pch = 24, cex = 3, 
             col = "white", fill = "darkred", lwd = 2)

p1 + as.layer(p2)

请注意,您也可以一次性完成此任务,而无需使用 latticeExtra,只需在 hexbinplot 中定义两个不同的 panel 函数,即

hexbinplot(y ~ x, mixdata, aspect = 1,
                 trans = sqrt, inv = function(x) x^2, 
                 panel = function(...) {
                   panel.hexbinplot(...)
                   panel.xyplot(3.5, 2.5, pch = 24, cex = 3, 
                                col = "white", fill = "darkred")
                 })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 2012-12-20
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多