我正在繪制兩個坐標之間的 voronoi 點。以便該點與資料框中的lower和upper值對齊。
不幸的是,當我繪制資料時,它會隨著點的值線性增加。這將產生以下情節:

這是我使用的腳本:
library(ggplot2)
library(ggvoronoi)
ggplot(voronoi_data, aes(x=lower, y=upper)) stat_voronoi() geom_point(aes(fit))
ggplot(voronoi_data, aes(x = lower, y = upper))
stat_voronoi(
geom = "path",
color = 4,
lwd = 0.7,
linetype = 1
) geom_point(aes(fit))
有些點不在 voronoi 圖內,因為它們要么太大要么太小。因此,我曾考慮將upper和lower值增加fit,并使用兩種不同的配色方案將兩個 voronoi 相互疊加,然后繪制fit值(這目前正在處理中,因為我剛剛有了這個想法。)
關于進度想法的更新:
voronoi_1 <-
mapply(function(a, b)
a - b, voronoi_data$lower, voronoi_data$fit) %>% data.frame(lower_add =
.)
voronoi_1 <-
rbind(
voronoi_1,
mapply(function(a, b)
a b, voronoi_data$lower, voronoi_data$fit) %>% data.frame(lower_add =
.)
)
voronoi_2 <-
mapply(function(a, b)
a b, voronoi_data$upper, voronoi_data$fit) %>% data.frame(upper_add =
.)
voronoi_2 <-
rbind(
voronoi_2,
mapply(function(a, b)
a - b, voronoi_data$upper, voronoi_data$fit) %>% data.frame(upper_add =
.)
)
voronoi_3 <- rep(voronoi_data$fit, 2) %>% data.frame(fit = .)
voronoi_update <- cbind(voronoi_1, voronoi_2, voronoi_3)
ggplot(voronoi_data, aes(x = lower, y = upper))
stat_voronoi(
geom = "path",
color = 4,
lwd = 0.7,
linetype = 1
) geom_point(aes(fit), col = 'blue') stat_voronoi(
data = voronoi_update,
aes(x = lower_add, y = upper_add),
geom = "path",
color = 2,
lwd = 0.7,
linetype = 1
) geom_point(col = 'green') geom_segment(aes(
x = lower,
y = upper,
xend = fit,
yend = fit
))
更新產生以下圖片:

我怎樣才能得到green-dots連接blue-dots?
可重現的資料:
structure(list(lower = c(-50.231394143356, -56.2551026846824,
28.4249214917657, -72.7725910398994, -81.2658846682781, 21.6407972918016,
-6.38857800084765, -83.9469403037355, -7.49345446155375, -9.25035611734441
), upper = c(83.3536041213786, 63.9866816320508, 145.329559457229,
48.0937531194102, 42.462115738722, 136.959651947817, 100.752432092854,
40.2250494139988, 110.279218627158, 107.6295802627), fit = c(16.5611049890113,
3.86578947368421, 86.8772404744972, -12.3394189602446, -19.4018844647781,
79.3002246198091, 47.1819270460033, -21.8609454448684, 51.3928820828022,
49.1896120726776)), class = "data.frame", row.names = c(NA, -10L
))
uj5u.com熱心網友回復:
您的積分不在 Voronoi 中的原因是您已經放入了aes(fit)里面geom_point。這被解釋為點的 x 軸值,這可能不是您想要的:
ggplot(voronoi_data, aes(x = lower, y = upper))
stat_voronoi(
geom = "path",
color = 4,
lwd = 0.7,
linetype = 1
) geom_point()

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/487265.html
