[Biological Information Analysis] Can a lollipop create a picture? R language to draw lollipop graph

Introduction to Lollipop Pictures

Simply put, is an alternative to bar charts, but it can display richer information than histograms

Just go ahead and show you the lollipop picture I drew:

Basic drawing method of lollipop picture

Lollipop chart colored by grouping variable "cyl":

ggdotchart(dfm, x = "name", y = "mpg",
           color = "cyl",                                # 按组显示颜色
           palette = c("#00AFBB", "#E7B800", "#FC4E07"), # 自定义调色板
           sorting = "ascending",                        # 按降序对值排序
           add = "segments",                             # 添加从y=0到点的线段
           ggtheme = theme_pubr()                        # 主题
           )

Add sorting, rotation, point size, numbers

  • Sort in descending order:sorting = "descending".
  • Vertical rotation: rotate = = TRUE 
  • Sort by mpg value within each group:group = "cyl"
  • GeneralDot sizeConfiguration: dot.size=6
  • Add mpg value as label. label = "mpg" or label = round(dfm$mpg)
ggdotchart(dfm, x = "name", y = "mpg",
           color = "cyl",                                # 按组显示颜色
           palette = c("#00AFBB", "#E7B800", "#FC4E07"), # 自定义调色板
           sorting = "descending",                       # 按降序对值排序
           add = "segments",                             # 添加从y=0到点的线段
           rotate = TRUE,                                # 垂直旋转
           group = "cyl",                                # 按组排序
           dot.size = 6,                                 # 点大小
           label = round(dfm$mpg),                       # 将mpg值添加为点标签
           font.label = list(color = "white", size = 9, 
                             vjust = 0.5),               # 调整标签参数
           ggtheme = theme_pubr()                        # ggplot2主题
           )

Add bias

  • Change segment color and size: add.params = list(color = “lightgray”, size = 2)
ggdotchart(dfm, x = "name", y = "mpg_z",
           color = "cyl",                                # 按组显示颜色
           palette = c("#00AFBB", "#E7B800", "#FC4E07"), # 自定义调色板
           sorting = "descending",                       # 按降序排序值
           add = "segments",                             # 添加从y=0到点的分段
           add.params = list(color = "lightgray", size = 2), # 添加从y=0到点的分段
           group = "cyl",                                # 按组排序
           dot.size = 6,                                 # 点大小
           label = round(dfm$mpg_z,1),                   # 将mpg值添加为点标签
           font.label = list(color = "white", size = 9, 
                             vjust = 0.5),               # 调整标签参数
           ggtheme = theme_pubr()                        # ggplot2主题
           )+
  geom_hline(yintercept = 0, linetype = 2, color = "lightgray")

Group color matching

  • Color y text by group (use y.text.col = TRUE):
 
  
ggdotchart(dfm, x = "name", y = "mpg",
           color = "cyl",                                # 分组颜色
           palette = c("#00AFBB", "#E7B800", "#FC4E07"), # 自定义调色板
           sorting = "descending",                       # 按降序对值进行排序
           rotate = TRUE,                                # 垂直旋转
           dot.size = 2,                                 # 点尺寸
           y.text.col = TRUE,                            # 按组为y文本上色
           ggtheme = theme_pubr()                        # ggplot2主题
           )+
  theme_cleveland()                                      # 添加虚线网格

To learn more, please visit:

kassambara/ggpubr: 'ggplot2' Based Publication Ready Plots (github.com) 

Guess you like

Origin blog.csdn.net/m0_61164319/article/details/134086468