R绘制横状条图并排序

R绘制横状条图并排序及一页多图

所用数据详情

institution
# A tibble: 10 x 2
   Institution                                     Articles
   <chr>                                              <dbl>
 1 Harvard Medical School                               177
 2 University of Texas MD Anderson Cancer Center        131
 3 Mayo Clinic                                          119
 4 Massachusetts General Hospital                       118
 5 Cleveland Clinic Foundation                          110
 6 Brigham and Women's Hospital                          93
 7 Seoul National University College of Medicine         88
 8 VA Medical Center                                     88
 9 Samsung Medical Center, Sungkyunkwan University       85
10 SungKyunKwan University, School of Medicine           78

所用绘制代码

 pacman::p_load(ggplot2,readr,forcats)
  institution <- read_csv("institution.csv")
  
  ggplot(institution,aes(x=reorder(Institution,Articles), y=Articles)) +  #reorder调整排列顺序
    geom_bar(stat = "identity", fill="steelblue4", color="black", width = 0.5, position = position_dodge(0.3))+#调整条形宽度以及条形距离 )+ 
    coord_flip()+
    geom_text(aes(label=Articles), hjust=-0.2, color="black")+
    xlab("Institution") + ylab("Articles")#可以通过color、size等自行调整标签属性
    
  # colours()[grep('blue', colours())]查看调整颜色

所得图像为
R绘制横状条图并排序_第1张图片

#一页多图
pacman::p_load(ggplot2,readr,forcats,showtext,cowplot)
institution <- read_csv("institution.csv")

#图一
plot.institution <- ggplot(institution,aes(x=reorder(Institution,Articles), y=Articles)) +  #reorder调整排列顺序
  geom_bar(stat = "identity", fill="steelblue4", color="black", width = 0.5, position = position_dodge(0.3))+#调整条形宽度以及条形距离 )+ 
  coord_flip()+
  geom_text(aes(label=Articles), hjust=-0.2, color="black")+
  xlab("Institution") + ylab("Articles")#可以通过color、size等自行调整标签属性
#图二
institute <- read_csv("institute.csv")

plot.institute <-ggplot(institute,aes(x=reorder(Institute,Articles), y=Articles)) +  #reorder调整排列顺序
  geom_bar(stat = "identity", fill="steelblue4", color="black", width = 0.5, position = position_dodge(0.3))+#调整条形宽度以及条形距离 )+ 
  coord_flip()+
  geom_text(aes(label=Articles), hjust=-0.2, color="black")+
  xlab("Institute") + ylab("Articles")#可以通过color、size等自行调整标签属性
# 组合方法一
p <- cowplot::plot_grid(plot.institution, plot.institute, nrow = 1, labels = LETTERS[1:2])#将2幅图组合成一幅图,按照一行两列排列,标签分别为A、B。(LETTERS[1:4] 意为提取26个大写英文字母的前四个:A、B、C、D)
p
# 组合方法二
p2 <- ggpubr::ggarrange(plot.institution, plot.institute, nrow = 1, labels = c('A', 'B'), font.label = list(color = 'red'))

你可能感兴趣的:(R实践)