小编今天给大家分享的是ggpubr包绘制lollipop图相关方法。棒棒糖图(lollipop chart),其实就是一个垂线图,棒棒糖图传达了与柱形图或者条形图相同的信息,只是将矩形转变成线条,这样可减少展示空间,重点放在数据点上,从而看起来更加简洁、美观。相对柱形图与条形图,棒棒糖图更加适合数据量比较多的情况。

library(ggplot2)library(ggpubr) inputFile="input_2.txt"outFile="Lollipop.pdf"outFile1="Lollipop1.pdf"setwd("C:\\Users\\admin\\Documents\\RStudio\\30.Lollipop") rt=read.table(inputFile,header=T,sep="\t",check.names=F)

pdf(file=outFile,width=7,height=6) ggplot(rt,aes(x=Term,y=Count))+ geom_hline(yintercept = 0,color="grey",size=1)+ geom_point(aes(color=ONTOLOGY),size=2)+ geom_bar(aes(file=ONTOLOGY),stat="identity",width = 0.2)+ theme_bw(base_family = "Times")+ theme(panel.grid.minor = element_blank(), panel.grid.major.x=element_blank(), axis.text.x=element_text(angle = 90), legend.position = "None", panel.border = element_blank())+labs(x="Count",y="Term",colour="",linetype="",file="")dev.off()

#ggpubr包绘制pdf(file=outFile1,width=7,height=6)ggdotchart(rt, x="Term", y="Count", color = "ONTOLOGY",group = "ONTOLOGY", #ggpubr包中ggdotchart()函数绘制 palette = "aaas", #配色方案 legend = "right", #图例位置 sorting = "descending", #上升排序,区别于descadd = "segments", #增加线段 dot.size = 5, #设置圆圈大小 label = round(rt$Count), #圆圈内数值 font.label = list(color="white",size=9, vjust=0.5), #圆圈内数值字体,颜色设置 rotate = T, #横向显示,设置为rotate=F便是纵向显示 ggtheme = theme_pubr())dev.off()

END
https://www.cloudtutu.com/