我正在嘗試在geom_histogram()ggplot 中繪制一些注釋。見下圖。這些注釋是每個 bin、每個組的直方圖計數。但是,當計數相似時,我不知道如何區分不同的注釋。vjust我只知道用or來修復注釋,hjust但我想知道是否有相對的方式。我認為沒有必要舉例。對于更有經驗的人來說,可能只看我的代碼會很容易。
這是我使用的代碼:
bind_rows(
RN_df %>% mutate(type='RN'),
RVNM_df %>% mutate(type='RVM')
) %>% group_by(hash) %>%
summarise(n_eps = n(), genre, type) %>%
ggplot(aes(x = n_eps, fill = genre))
geom_histogram(binwidth = 1)
stat_count(aes(y=..count..,label=..count.., colour = genre),geom="text",vjust= -1, hjust = 0.5, size = 3)
facet_wrap(~type)
這是我的輸出影像:

uj5u.com熱心網友回復:
您可以使用geom_text_repel來自ggrepel:
library(ggrepel)
ggplot(df, aes(x = n_eps, fill = genre))
geom_histogram(binwidth = 1)
geom_text_repel(aes(label = ..count..), stat = 'count',
position = position_stack(vjust = 0.5), direction = 'y')
facet_wrap(~type)

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/466717.html
上一篇:如何在y軸上排序時間
