각각에 대한 평균 헤딩을 계산하기 위해 2D 빈으로 나누고 자하는 x, y 좌표 및 헤딩 각도로 구성된 데이터가 있습니다 빈과 ggplot
의 geom_spoke
와 줄거리.`geom_spoke`에 전달하기 전에 X, Y, 쎄타 데이터를 2D bin으로 요약하십시오.
# heatmap of x,y counts
p <- ggplot(dat, aes(x, y)) +
geom_bin2d(binwidth = c(50, 50)) +
coord_equal()
#ggplot_build(p)$data[[1]] #access binned data
:
# data
set.seed(1)
dat <- data.frame(x = runif(100,0,100), y = runif(100,0,100), angle = runif(100, 0, 2*pi))
# manual binning
bins <- rbind(
#bottom left
dat %>%
filter(x < 50 & y < 50) %>%
summarise(x = 25, y = 25, angle = mean(angle), n = n()),
#bottom right
dat %>%
filter(x > 50 & y < 50) %>%
summarise(x = 75, y = 25, angle = mean(angle), n = n()),
#top left
dat %>%
filter(x < 50 & y > 50) %>%
summarise(x = 25, y = 75, angle = mean(angle), n = n()),
#top right
dat %>%
filter(x > 50 & y > 50) %>%
summarise(x = 75, y = 75, angle = mean(angle), n = n())
)
# plot
ggplot(bins, aes(x, y)) +
geom_point() +
coord_equal() +
scale_x_continuous(limits = c(0,100)) +
scale_y_continuous(limits = c(0,100)) +
geom_spoke(aes(angle = angle, radius = n/2), arrow=arrow(length = unit(0.2,"cm")))
내가 각 빈에 대한 계수 데이터를 포함하는 2D 방식, 예를 만드는 방법을 알고 여기에
그러나 geom_spoke
으로 전달하기 전에 각 bin의 제목과 같은 다른 변수를 요약하는 방법을 찾지 못하는 것 같습니다. 첫 번째 비닝이 없으면 내 플롯은 다음과 같이 보입니다.
이 Z.Lin @ 환상적이다, 대단히 감사합니다! 전에 사용하지 않은'rowwise()'함수의 위대한 예 :) – jogall