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

科研菌
关注

ggtheme

设置画图主题,默认是theme_pubr()。

ggplot2 official themes: theme_gray(), theme_bw(), theme_minimal(), theme_classic(), theme_void()


棒棒糖图

# 棒棒图可以代替条形图展示数据,用到的数据是df5(柱状图多单调,改用棒棒糖图添加多样性哦~)ggdotchart(df5, x="name", y="mpg", color = "cyl",           palette = c("#00AFBB", "#E7B800", "#FC4E07"),           sorting = "ascending",           add = "segments", ggtheme = theme_pubr())

#设置分组:ggdotchart(df5, x="name", y="mpg", color = "cyl",group = "cyl",               palette = c("#00AFBB", "#E7B800", "#FC4E07"),                      sorting = "ascending",                      add = "segments", ggtheme = theme_pubr())

# 坐标轴变换ggdotchart(df5, x="name", y="mpg", color = "cyl",           palette = c("#00AFBB", "#E7B800", "#FC4E07"),           sorting = "descending", add = "segments", rotate = TRUE,           group = "cyl",           ggtheme = theme_pubr())

# dot.size = 6调整糖的大小,label = round添加糖心中的数值,font.label进一步设置字体样式ggdotchart(df5, x="name", y="mpg", color = "cyl",          palette = c("#00AFBB", "#E7B800", "#FC4E07"),          sorting = "descending", add = "segments", rotate = TRUE,          group = "cyl", dot.size = 6,          label = round(df2$mpg), # round函数表示四舍五入          font.label = list(color="white",size=9, vjust=0.5), # vjust 调节 label 和糖心的相对位置          ggtheme = theme_pubr())

ggdotchart 函数:用法:ggdotchart(data, x, y, group = NULL, combine = FALSE, color = "black",           palette = NULL, shape = 19, size = NULL, dot.size = size,           sorting = c("ascending", "descending"), add = c("none", "segment"),           add.params = list(), x.text.col = TRUE, rotate = FALSE, title = NULL,           xlab = NULL, ylab = NULL, facet.by = NULL, panel.labs = NULL,           short.panel.labs = TRUE, select = NULL, remove = NULL, order = NULL,           label = NULL, font.label = list(size = 11, color = "black"),           label.select = NULL, repel = FALSE, label.rectangle = FALSE,           ggtheme = theme_pubr(), ...)           theme_cleveland(rotate = TRUE)

参数:

data

所需的数据框 dataframe

x,y

进行作图所需的数据

group

分组变量(x轴方向上)

combine

对于多个变量的数据是否分面

声明: 本文由入驻OFweek维科号的作者撰写,观点仅代表作者本人,不代表OFweek立场。如有侵权或其他问题,请联系举报。
侵权投诉

下载OFweek,一手掌握高科技全行业资讯

还不是OFweek会员,马上注册
打开app,查看更多精彩资讯 >
  • 长按识别二维码
  • 进入OFweek阅读全文
长按图片进行保存