Re: [問題] ggplot2請教

作者: celestialgod (天)   2015-06-04 10:44:00
※ 引述《ardodo (米蟲)》之銘言:
: 更新一下自己的問題,我想要在ggplot上按照y值總合大小排序我的x類別,以下code
: #Data
: hp=read.csv(textConnection(
: "class,year,amount
: a,99,100
: a,100,200
: a,101,150
: b,100,50
: b,101,100
: c,102,70
: c,102,80
: c,103,90
: c,104,50
: d,102,90"))
: hp$year=as.factor(hp$year)
推文推太快,複製貼上錯,造成誤會,對不起
levels(hp$class) = levels(hp$class)[
order(tapply(hp$amount, hp$class, sum),decreasing = TRUE)]
: #Plotting
: p=ggplot(data=hp)
: p+geom_bar(binwidth=0.5,stat="identity")+ #
: aes(x=class,y=amount,label=amount,fill=year)+theme()
作者: ardodo (米蟲)   2015-06-04 10:57:00
感謝cel大回覆,可是我的需求是把ggplot2的x軸依照各類別amount的總合降冪排序,也就是a>c>b>d,而不是單純的更換class的名稱

Links booklink

Contact Us: admin [ a t ] ucptt.com