首页 > 解决方案 > 使用坐标翻转从上到下

问题描述

像这样使用 ggplot 时

data_frame(diamonds)

ggplot(diamonds,aes(cut)) +
  geom_bar() 

我得到了预期的情节,但是当我这样做时:

ggplot(diamonds,aes(cut)) +
  geom_bar() +
  coord_flip()

我翻转了绘图,但新的“y”值从下到上,是否可以翻转坐标并使值从上到下?所以“公平”将是最有价值的,然后是“好”,然后是“非常好”......等等。

在此处输入图像描述

标签: rggplot2

解决方案


我们可以fct_rev使用forcats

library(forcats)
library(ggplot2)
ggplot(diamonds, aes(fct_rev(cut))) +
       geom_bar() +
       coord_flip() + 
       xlab('cut')

在此处输入图像描述


推荐阅读