위도, 경도 및 개수 형식의 고객 데이터가 일부 제공되었습니다. ggplot 히트 맵을 생성하는 데 필요한 모든 데이터가 있지만 ggplot이 요구하는 형식으로 데이터를 저장하는 방법을 모르겠습니다.ggplot 사용을위한 위도, 경도 및 개수 요약 데이터
데이터를 0.01 Lat 및 0.01 Lon 블록 (일반적인 히트 맵) 내에서 총계하여 집계하려고하며 본능적으로 "tapply"라고 생각했습니다. 원하는대로 블록 크기별로 멋진 요약을 만들지 만 형식이 잘못되었습니다. 더구나, 나는 거기에 아무것도 없더라도, 빈 Lat 또는 Lon 블록 값을 0으로 포함 시키길 정말로 원합니다. 그렇지 않으면 히트 맵이 이상하고 이상하게 보입니다.
귀하의 도움에 감사드립니다.
나는 아래의 코드에서 참조 용으로 내 데이터의 하위 집합을 만들었습니다
여기# m is the matrix of data provided
m = matrix(c(44.9591051,44.984884,44.984884,44.9811399,
44.9969096,44.990894,44.9797023,44.983334,
-93.3120017,-93.297668,-93.297668,-93.2993524,
-93.2924484,-93.282462,-93.2738911,-93.26667,
69,147,137,22,68,198,35,138), nrow=8, ncol=3)
colnames(m) <- c("Lat", "Lon", "Count")
m <- as.data.frame(m)
s = as.data.frame((tapply(m$Count, list(round(m$Lon,2), round(m$Lat,2)), sum)))
s[is.na(s)] <- 0
# Data frame "s" has all the data, but not exactly in the format desired...
# First, it has a column for each latitude, instead of one column for Lon
# and one for Lat, and second, it needs to have 0 as the entry data for
# Lat/Lon pairs that have no other data. As it is, there are only zeroes
# when one of the other entries has a Lat or Lon that matches... if there
# are no entries for a particular Lat or Lon value, then nothing at all is
# reported.
desired.format = matrix(c(44.96,44.96,44.96,44.96,44.96,
44.97,44.97,44.97,44.97,44.97,44.98,44.98,44.98,
44.98,44.98,44.99,44.99,44.99,44.99,44.99,45,45,
45,45,45,-93.31,-93.3,-93.29,-93.28,-93.27,-93.31,
-93.3,-93.29,-93.28,-93.27,-93.31,-93.3,-93.29,
-93.28,-93.27,-93.31,-93.3,-93.29,-93.28,-93.27,
-93.31,-93.3,-93.29,-93.28,-93.27,69,0,0,0,0,0,0,
0,0,0,0,306,0,0,173,0,0,0,198,0,0,0,68,0,0),
nrow=25, ncol=3)
colnames(desired.format) <- c("Lat", "Lon", "Count")
desired.format <- as.data.frame(desired.format)
minneapolis = get_map(location = "minneapolis, mn", zoom = 12)
ggmap(minneapolis) + geom_tile(data = desired.format, aes(x = Lon, y = Lat, alpha = Count), fill="red")
geom_hex 및 stat_density2d와 같은 "기본"솔루션을 살펴 보았습니까? – ako
아코 ... 아니야. 나는이 특별한 종류의 시각화에 비교적 익숙하지 않으며 조사를위한 새로운 방향을 고맙게 생각합니다. 나는이 두 가지를 살펴볼 것이다. 고맙습니다. – rucker
아코 ... 그냥 geom_hex를 살펴 봤는데 같은 형식을 찾고있는 것 같습니다. 근본적인 문제는 ggplot이 행당 개수 값이 아니라 각 행에 대해 개별 항목을 필요로한다는 것입니다. 상황을 악화시키는 것은 이러한 카운트 값을 히트 맵 (또는 헥스 맵)에 원하는 공간적 위치로 집계해야한다는 것입니다. – rucker