然后代码显示了不同分辨率的plotDomain方法。任何决议的单独代码。问:如何绘制所有分辨率,以便在一个图形上全部可见
软件包:CRAN中的任何软件包(但无需安装其他东西,例如Java或Python)
代码:
rm(list = ls())
library(R6)
library(hexbin)
Domain <- R6Class(
"Domain",
public = list(
data = NULL,
resolution = NULL,
initialize = function(data, resolution) {
self$data <- data
self$resolution <- resolution
},
plotDomain = function(resolutionIndex, border = rgb(0, 1, 1, .3), col = "#9ecae1", alpha = 0.01) {
x <- self$data$x
y <- self$data$y
# Utworzenie mapy heksagonalnej
hex <- hexbin(x, y, xbins = self$resolution[resolutionIndex])
# Ustawienie parametrów dla linii
par(lwd = 1.5, lend = 2)
# Wyświetlenie mapy z przeźroczystym kolorem
plot(hex, colramp = colorRampPalette(rgb(t(col2rgb(col)/255), alpha = 0.05)),
border = border, legend = FALSE)
}
)
)
data <- read.csv("C:/Users/jerzy/OneDrive/Dokumenty/R Studio/test_data_00.csv")
#data <- read.csv(file = "./test_data_00.csv")
# Przygotowanie danych x i y
x <- data$x
y <- data$y
# Inicjalizacja obiektu klasy Domain
a <- Domain$new(data.frame(x = x, y = y), c(10, 20, 30))
graphics.off()
# Wywołanie metody plotDomain dla różnych rozdzielczości
a$plotDomain(resolutionIndex = 1)
a$plotDomain(resolutionIndex = 2)
a$plotDomain(resolutionIndex = 3)
我的结果:
预期结果:
1条答案
按热度按时间zf9nrax11#
理论上,您应该能够将
newpage
参数传递给hexbin的plot
方法,但在这里似乎不起作用。另一种方法是指定add = TRUE
将六边形添加到现有图中,但这意味着您需要以R为底计算和绘制六边形:您没有包含任何数据,但似乎任何一组x,y坐标都足以用于演示: