我有以下資料框:
df = structure(list(qCountry = c("AT", "DE", "ES", "FI", "FR", "GR",
"HU", "IR", "IT", "LV", "NL", "POL", "PT", "RO", "SWE"), Mean = c(1.34199395770393,
1.37664132688321, 1.29144095341278, 1.42088404868674, 1.45019920318725,
1.29786200194363, 1.24528301886792, 1.26937046004843, 1.38345864661654,
1.39706780696396, 1.38751714677641, 1.30804248861912, 1.28609062170706,
1.2320819112628, 1.32588699080158), Sd = c(0.474520963779525,
0.484711259139164, 0.454549282145671, 0.493859200850428, 0.497678958439859,
0.45742966912063, 0.430377930416405, 0.443767080631815, 0.48638085640142,
0.489439780963027, 0.487350499450418, 0.461801022550429, 0.452051373271304,
0.422281105345888, 0.468859354590332)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -15L))
我想將它結合起來geom_point和geom_errorbar. 這不是問題。但是,x 軸是一個連續變數,而我希望 ggplot 只顯示兩個標簽“是”和“否”,分別對應 1 和 2。我嘗試了以下方法,但它不起作用:
df %>% ggplot(aes(x = reorder(qCountry,-Mean), y = Mean, group = qCountry)) geom_point(size = 3.5)
geom_errorbar(aes(ymin=Mean-Sd, ymax=Mean Sd)) labs(title = "Some Title",x = "", y="") scale_y_discrete(labels= c("Yes", "No")) coord_flip() theme_classic2()
誰能幫我?
謝謝!
uj5u.com熱心網友回復:
你不能有一個離散的軸。但是您可以重新標記連續軸,使 1 為“否”,2 為“是”
df %>%
ggplot(aes(x = reorder(qCountry,-Mean), y = Mean, group = qCountry))
geom_point(size = 3.5)
geom_errorbar(aes(ymin=Mean-Sd, ymax=Mean Sd))
labs(title = "Some Title",x = "", y="")
scale_y_continuous(breaks = c(1, 2),
labels = c("No", "Yes"), limits = c(0.8, 2))
coord_flip()
theme_classic(base_size = 20)

提醒一下,您可能想看看您是如何計算標準偏差的,因為您的誤差線延伸到 1 以下,這實際上沒有任何意義。您可能想要計算二項式置信區間。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/474412.html
