如何解决对小节的条进行排序
我的数据集如下:
bioassay
# A tibble: 8 x 6
# Groups: treatment.tx,date,combinedwith.tx [8]
treatment.tx date combinedwith.tx conc mean_hatch stdev_hatch
<chr> <fct> <chr> <fct> <dbl> <dbl>
1 8cG_.2mM_200527 200527 none 200 25.3 6.31
2 8cG_1mM_200527 200527 none 1000 57.7 8.25
3 8cG_1mM_atr5mM_200702 200702 atropine5mM 1000 30.8 6.45
4 8cG_1mM_dfd50uM_200702 200702 dafadine50uM 1000 23.6 6.27
5 8cG_1mM_ktc500uM_200702 200702 ketoconazole500uM 1000 14.1 9.76
6 8cG_1mM_LY500uM_200702 200702 LY500uM 1000 28.4 6.47
7 8cG_2.5mM_200527 200527 none 2500 57.7 8.13
8 8cG_5mM_200507 200507 none 5000 40.7 5.53
小标题的内容
structure(list(treatment.tx = c("8cG_.2mM_200527","8cG_1mM_200527","8cG_1mM_atr5mM_200702","8cG_1mM_dfd50uM_200702","8cG_1mM_ktc500uM_200702","8cG_1mM_LY500uM_200702","8cG_2.5mM_200527","8cG_5mM_200507"
),date = structure(c(2L,2L,3L,1L),.Label = c("200507","200527","200702"),class = "factor"),combinedwith.tx = c("none","none","atropine5mM","dafadine50uM","ketoconazole500uM","LY500uM","none"),conc = structure(c(1L,4L),.Label = c("200","1000","2500","5000"),mean_hatch = c(25.2525252525253,57.7160062183685,30.7640235581412,23.5513647506745,14.1329043365367,28.3725235338139,57.6624355184606,40.6641760066418),stdev_hatch = c(6.30807878626101,8.2511325192673,6.45000163857553,6.26978502069754,9.75908792638684,6.47448596773916,8.13374952479032,5.52569421842133)),row.names = c(NA,-8L
),groups = structure(list(treatment.tx = c("8cG_.2mM_200527","8cG_5mM_200507"),.rows = structure(list(
1L,4L,5L,6L,7L,8L),ptype = integer(0),class = c("vctrs_list_of","vctrs_vctr","list"))),class = c("tbl_df","tbl","data.frame"),.drop = TRUE),class = c("grouped_df","tbl_df","data.frame"))
我想制作一个按日期排序的小图。我写了以下内容:
bioassay$date <- factor(bioassay$date,levels=c("200507","200702"))
但是,这不会对我的情节中的小节或小节进行排序:
ggplot(data=bioassay,aes(fill=combinedwith.tx,x=treatment.tx,y=mean_hatch)) +
geom_bar(stat='identity',width=0.5,alpha=0.5) +
geom_errorbar(aes(ymin=mean_hatch-stdev_hatch,ymax=mean_hatch+stdev_hatch),width=0.2,size=0.5) +
theme_light() +
labs(fill = "combined with") +
theme(text=element_text(size=15),axis.text.x=element_text(angle=45,hjust=1)) +
scale_fill_manual(values=c("yellow2","darkgreen","red2","blue","grey0")) +
scale_x_discrete(name = "combined with inhibitor") +
scale_y_continuous(name = 'hatching (%)',limits=c(0,66),breaks=c(-20,20,40,60,80,100)
)
给出以下内容:
到处都有我发现上述代码行应该是解决方案。
解决方法
在ggplot中尝试此aes
aes(fill=combinedwith.tx,x=reorder(treatment.tx,dateorder),y=mean_hatch)
其中dateorder
是一个新的数字变量,按照您希望显示条形的顺序。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。