楼主: aaasssdddwww
2361 1

[问答] ggplot2簇状柱图如何按降序排列 [推广有奖]

  • 0关注
  • 0粉丝

等待验证会员

初中生

47%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
66 点
帖子
6
精华
0
在线时间
16 小时
注册时间
2019-1-4
最后登录
2019-5-5

楼主
aaasssdddwww 发表于 2019-5-5 03:42:21 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
cmn
Sweden2014454088
Nordic countries201446019
European countries201425068
Other countries201417100
Sweden2015485509
Nordic countries201544467
European countries201526994
Other countries201514261
Sweden2016542091
Nordic countries201651562
European countries201633767
Other countries201616360
Sweden2017560829
Nordic countries201756723
European countries201734139
Other countries201723839
Sweden2018548372
Nordic countries201856441
European countries201844513
Other countries201834174


数据表如图,代码如下:

ggplot(summary,aes(x=m,y=n,fill=c,label=n))+
  geom_bar(stat="identity",position="dodge")+
  theme_wsj(color="white")+
  scale_fill_wsj("rgby", "")+
  scale_y_continuous(breaks = seq(50000,800000,100000))+
  theme(axis.ticks.length=unit(0.5,'cm'))+
  guides(fill=guide_legend(title=NULL))+
  theme(axis.title = element_blank())
  geom_text(aes(y = n + 0.05), position = position_dodge(0.9), vjust = -0.5)


数据出图如下,问题是,如何将柱图在每年内按降序排列?

代码出图
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:ggplot2 gplot plot 降序排列 GPL

沙发
cheetahfly 在职认证  发表于 2019-5-5 09:33:49
  1. summary %>%
  2.     mutate(c = factor(c, levels = c("Sweden", "Nordic countries", "European countries", "Other countries"))) %>%
  3.     ggplot(aes(x = m, y = n, fill = c))+
  4.     geom_bar(stat="identity", position="dodge")+
  5.     theme_wsj(color="white")+
  6.     scale_fill_wsj("rgby", "")+
  7.     scale_y_continuous(breaks = seq(50000,800000,100000))+
  8.     theme(axis.ticks.length=unit(0.5,'cm'))+
  9.     guides(fill=guide_legend(title=NULL))+
  10.     theme(axis.title = element_blank()) +
  11.     geom_text(aes(y = n + 0.05, label = paste0(round(n / 1e3, 1), "K")), position = position_dodge(0.9), vjust = -0.5)
复制代码


重新排列.png
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Sunknownay + 3 + 3 + 3 精彩帖子

总评分: 学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-10 20:49