我想知道是否有辦法在我的條形圖中勾勒出條形。我想在一組條形圖中勾勒出條形圖的左邊、上面和右邊,然后再勾勒出一組聚集在一起的條形圖。我已經嘗試了一下,但沒有什么收獲。我不完全確定這是否可行。我將附上我的資料、圖表的一些代碼,以及我希望圖表看起來像什么的一些圖片
。library(ggplot2)
ggplot(df, aes(bar,num, 填充= group))
geom_bar(stat = 'ident', 寬度 = 5)
scale_fill_manual(values =alpha(c("blue"/span>)。 . 3))。
下面是資料
df < -結構(list(bar = c(17. 5, 27. 5, 32.5, 37.5, 42. 5, 47.5, 52.5,
57.5, 62.5, 67. 5, 72.5, 77.5, 82. 5)。 num = c(1L。 7L, 8L。 11L,
22L, 46L, 43L。 60L, 59L, 40L。 17L, 11L。 1L)。 組=結構(c(1L。
1L, 1L,。 1L, 1L, 1L。 1L, 1L, 1L。 1L, 1L, 1L), 。 標簽 = "A"。 class = "factor"))。 class = "data. frame",行。 names = c(NA,)
-13L))
而這是我希望做出的東西
uj5u.com熱心網友回復:
你可以黑掉geom_step,通過添加零長度條來做到這一點。
zeroes < - setdiff(seq(min(df$bar)。 max(df$bar) 5。 由= 5)。 df$bar)
df2 <- rbind(df,/span> data. frame(bar = min(df$bar)。 num = 0。 組 = "A"))
df2 <- rbind(df2, data. frame(bar = zeroes, num = 0。 組 = "A"))
df2 <- df2 %>% arrange(bar, num)
library(ggplot2)
ggplot(df2, aes(bar,num, 填充= group))
geom_bar(stat = 'ident', , width = 5)
geom_step(col = 'red, aes(x = bar - 2. 5))
scale_fill_manual(values = alpha(c("blue"/span>)。 . 3))。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/318922.html
標籤:
上一篇:在AirPassengers資料集中使用ggplot
下一篇:每個單位有輪廓的柱狀圖?


