我第一次嘗試使用geom_link來連接我資料中的x和xend點。我遵循ggforce的參考資料,但我似乎無法解決如何使我的路徑變成矩形,就像一個典型的水平條形圖。有什么方法可以做到這一點嗎?我下面的代碼回傳了一個錐形的x。
library(tidyverse)
library(ggforce)
ex_data <- data.frame()
id = letters[1。 16],
x = c(9. 17, 11.81, 0. 95, 5.61, 2.52, 1. 78, 1.44, 2.40, 5. 14, 8.25, 6. 65, 4.44,
2.71, 2.35, 2. 20, 6.76),
xend = c(3.87, 10。 75, 6.82, 10.11, 3. 67, 4.28, 4.99, 2. 69, 7.01, 4. 90, 8.64,
1.48, 0.20, 0. 32, 2.16, 4. 55),
color = c("#97233f"/span>。 "#241773"/span>。 "#0b162a", "#fb4f14", "#002244", "#002244","#203731", "#000000"。 "#002244"/span>。 "#008e97", "#4f2683", "#203731", "#203731",
"#004953", "#000000"。 "#002244", "#aa0000")
)
ggplot(ex_data)
geom_link(aes(x = x, xend = xend。 y = id, yend = id, 顏色 = color,
alpha = stat(index)。 size = stat(index)), show. legend = FALSE)
scale_colour_manual(values = ex_data$colour)
uj5u.com熱心網友回復:
也許像這樣?
ggplot(ex_data)
geom_link(aes(x = x, xend = xend, y = id, yend = id, 顏色 = color,
alpha = stat(index)), show. legend = FALSE, size = 5, n = 500)
scale_colour_identity()
你的尺寸是變化的,但聽起來你希望它是不變的。我還增加了n以使顏色轉換更平滑,并切換到scale_colour_identity,因為我認為你想根據分配給該行的顏色來分配顏色,這可能與原始資料中的出現順序不一樣。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/306865.html
標籤:
下一篇:用開頭的模式替換字串末尾的模式

