美文网首页
ggplot2-ggpie

ggplot2-ggpie

作者: 汪汪2017 | 来源:发表于2017-11-01 08:52 被阅读0次
data = read.table("6_fo_go.txt.Level2.count.txt", header = F, sep = "\t", fileEncoding = "UTF-16")    #读取文件读取不出来考虑下文件编码问题
library("magrittr")
library("ggpubr")
#data[,2]=data[,2]*100/sum(data[,2])      #求百分比数字
df <- data.frame(
                 group = data[,1],
                 value = round(data[,2],2))      #round 可以用来保留小数位数
#View(df)      #查看画图的准备数据
#labs <- paste0(" (", df$value, "%)")        #设置标签内容
ggpie(df,"value",
      #label = labs,                                      #设置标签
      #lab.pos = "out", lab.font = "white",    #放置标签到饼图扇形区域,并设置标签颜色
      fill = "group",color = "white",
      palette = get_palette("Set1",20))        #设置饼图的颜色,Set1是颜色集名称,接着的数字是需要的颜色个数,设置个数小于分类个数会报错,为了方便可以直接放一个较大的数字

相关文章

网友评论

      本文标题:ggplot2-ggpie

      本文链接:https://www.haomeiwen.com/subject/rerwpxtx.html