0
我試圖找到一種方法來輕鬆地翻轉用geom_text()註釋的情節。問題是,如果我使用coord_flip(),標籤是沒有翻轉的。ggplot2 coord_flip()with geom_text
一個簡單的例子,如果我翻轉這樣的情節:加入coord_flip()
df <- count(diamonds, cut)
ggplot(df, aes(x = cut, y = n, label = n)) +
geom_bar(stat = "identity") +
geom_text()
我知道,這可能在某些情況下,這是一種理想的行爲,但相反,我需要酒吧上的標籤與酒吧保持一致,看起來更像:
有沒有解決方法?
爲了增強可讀性,爲什麼不離開文本中的水平?你可以做,例如,'ggplot(df,aes(x = cut,y = n,label = format(n,big.mark =「,」)))+ geom_bar(stat =「identity」)+ geom_text(aes(y = 0.5 * n),color =「white」)+ coord_flip()'。 – eipi10