想要的圖
我想獲得上面的圖表,并嘗試使用 ggplot 來獲取它。
blue = c(83, 81, 80, 71, 69, 63, 63, 62, 54)
red = c(112, 96, 111, 141, 125, 89, 178, 107, 130)
loc = c("YISHUN", "WOODLANDS", "HOUGANG", "ANG MO KIO" "TAMPINES", "SENGKANG", "GEYLANG", "BEDOK", "JURONG WEST")
tib = mutate(blue, red, loc)
ggplot(lst_compare, aes(x=c(wet, dry) ,y=loc))
geom_point() geom_segment(y=loc, x= wet, xend= dry, yend= loc)
我嘗試了上述方法,但是,似乎不能簡單地將多列包含為 x 值。有誰知道如何將多列作為 x 軸的一部分?
uj5u.com熱心網友回復:
我修正了你的 reprex 中的錯誤。我認為最好在繪圖之前對資料進行透視。
library(tidyverse)
blue = c(83, 81, 80, 71, 69, 63, 63, 62, 54)
red = c(112, 96, 111, 141, 125, 89, 178, 107, 130)
loc = c("YISHUN", "WOODLANDS", "HOUGANG", "ANG MO KIO", "TAMPINES", "SENGKANG", "GEYLANG", "BEDOK", "JURONG WEST")
tib = data.frame(blue, red, loc)
tib %>%
pivot_longer(c("blue", "red")) %>%
ggplot()
geom_point(aes(x = value, y = loc, color = name), size = 2)
scale_color_identity()
geom_line(aes(x = value, y = loc))
theme_minimal()

由reprex 包(v2.0.1)于 2021 年 10 月 21 日創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/335796.html
上一篇:位置文本條形圖堆疊ggplot2
