R 语言条形图,解决x轴文字排序问题

数据结果的图形展示,R代码,《R数据科学》是个好东西

数据格式如下:

termcategorypval
neutrophil chemotaxisbiological_process1.68E-09
innate immune responsebiological_process3.35E-09
complement activation, classical pathwaybiological_process1.14E-08
negative regulation of endopeptidase activitybiological_process4.43E-08
collagen fibril organizationbiological_process4.43E-08
blood coagulationbiological_process1.29E-07
proteolysis involved in cellular protein catabolic processbiological_process1.56E-07
proteolysisbiological_process1.13E-06
leukocyte migration involved in inflammatory responsebiological_process1.47E-06
peptide cross-linkingbiological_process1.47E-06
extracellular spacecellular_component8.75E-40
collagen-containing extracellular matrixcellular_component2.08E-26
extracellular matrixcellular_component5.72E-11
lysosomecellular_component6.09E-10
extracellular regioncellular_component6.58E-10
collagen trimercellular_component1.68E-09
cell surfacecellular_component2.80E-08
extracellular exosomecellular_component2.34E-07
extrinsic component of external side of plasma membranecellular_component1.47E-06
sarcolemmacellular_component3.16E-06

 

作图要求:x轴为term,颜色按categroy分类、并且pval由小到大排序

代码:

#openxlsx读入为data.frame

class(data)

#转换
library(tidyverse)
godata<-as_tibble(godata)
class(godata)

#原始数据筛选(category,term,pval)散列,按照category,-log10(pval)排序

data<-godata%>%select(category,term,pval)%>%arrange(category,desc(-log10(pval)))

#画图时改变geom_bar的自动排序

data$term<-factor(data$term,levels = unique(data$term),ordered = T)

#作图

ggplot(data)+
  geom_bar(aes(x=term,y=-log10(pval),fill=category),stat = 'identity')+
  coord_flip()

结果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值