您现在的位置:首页 >> 农业机械厂家

ggpubr包绘图技巧分享饼图棒棒糖图Cleveland点图

2022-04-28 来源:河南农业机械网

ggpubr包绘图技巧分享:饼图、棒棒糖图、Cleveland 点图

先简单介绍一下今天要分享的绘图内容,分别有:饼图、棒棒糖图、Cleveland 点图。

接下来,先安装 ggpubr 包:

# Install from CRAN:install.packages("ggpubr")library(ggpubr)

饼图

# 先构建数据

df6 <- data.frame(group = c("Male", "Female", "Child"), value = c(25, 25, 50))

head(df6)

# group value# 1 Male 25# 2 Female 25# 3 Child 50

# 饼图基础模式ggpie(df6, "value", label = "group")

# 修改轮廓线颜色、填充色

ggpie(df6, "value", label = "group", fill = "group", color = "white", palette = c("#00AFBB", "#E7B800", "#FC4E07") )

# 修改标签为组名(比例)labs <- paste0(df5$group, " (", df5$value, "%)")labs# [1] "Male (25%)" "Female (25%)" "Child (50%)"

ggpie(df6, "value", label = labs, fill = "group", color = "white", palette = c("#00AFBB", "#E7B800", "#FC4E07"))

# 调整标签的位置和颜色ggpie(df6, "value", label = labs, lab.pos = "in", lab.font = "white", fill = "group", color = "white", palette = c("#00AFBB", "#E7B800", "#FC4E07"))

ggpie 函数:

用法:

ggpie(data, x, label = NULL, lab.pos = c("out", "in"), lab.adjust = 0, lab.font = c(4, "bold", "black"), color = "black", fill = "white", palette = NULL, size = NULL, ggtheme = theme_classic(), ...)

参数:

data

所需的数据框 dataframe

x

进行作图所需的数据

label

设置饼图每一部分的标签

lab.pos

设置 label 的位置,选项有:"out" (for outside) or "in" (for inside)

lab.adjust

当 lab.pos = "in" 时,调整 label 在饼图中的位置

lab.font

设置标签的字体:大小、类型(e.g.: "plain", "bold", "italic", "bold.italic")、颜色

如:lab.font= c(4, "bold", "red")

color, fill

轮廓线的颜色和填充色

palette

自定义颜色画板

size

设置点和轮廓线的大小

1234下一页>

黑魔方粉底液

玫瑰锁妆粉底液

美尚