R ggplot2坐标翻转(),带几何图形文字

R ggplot2坐标翻转(),带几何图形文字,r,ggplot2,R,Ggplot2,我正试图找到一种方法来轻松翻转带有geom_text()注释的绘图。问题是如果我使用coord_flip(),标签就不会翻转 一个简单的例子,如果我像这样翻转绘图: df <- count(diamonds, cut) ggplot(df, aes(x = cut, y = n, label = n)) + geom_bar(stat = "identity") + geom_text() df您可以在geom_text中使用角度美学,将其设置为固定值 ggplot(df, aes(x

我正试图找到一种方法来轻松翻转带有geom_text()注释的绘图。问题是如果我使用coord_flip(),标签就不会翻转

一个简单的例子,如果我像这样翻转绘图:

df <- count(diamonds, cut)

ggplot(df, aes(x = cut, y = n, label = n)) +
geom_bar(stat = "identity") +
geom_text()

df您可以在
geom_text
中使用
角度
美学,将其设置为固定值

ggplot(df, aes(x = cut, y = n, label = n)) +
    geom_bar(stat = "identity") +
    geom_text(angle = 270) +
    coord_flip()

为了便于阅读,为什么不将文本保持水平?例如,您可以执行以下操作:
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()