position参数设置,可以转换条形图形式
涉及到长宽数据转换
# 数据
Mountain 科 属 种
BMSM 88.28 68.95 40.3
GGM 86.21 72.72 48.87
GLGM 84.12 63.82 32.19
WL 86.69 67.3 36.72
#从剪贴板获取
library(tidyverse)
df = read.table("clipboard", header = TRUE, sep = "\\t")
# 字体
library(showtext)
font_add("ST_TNR", regular = "G:\\\\字体\\\\宋体和time new roman\\\\ST_TNR.ttf")
showtext_auto()
df %>%
gather(category, value, -Mountain) %>%
ggplot(aes(Mountain, value, fill = category))+
geom_bar(position = "dodge", stat = "identity", color="grey30", width = 0.8)+
labs(x = NULL, y = "相似性 Similarity/%", size = 10)+
ggthemes::theme_few()+
scale_y_continuous(expand = c(0,0,0,0), limits = c(0,100))+
theme(legend.title = element_blank(), legend.key.size = unit(0.8, "cm"), legend.position = c(0.94, 0.9), text = element_text(family = "ST_TNR"), axis.title = element_text(size = 15), axis.text = element_text(size = 14), axis.ticks.length.y = unit(-0.2,"cm"), axis.ticks.length.x = unit(0,"cm"), panel.border =element_blank(), axis.line = element_line(color = 'black'))+
guides(fill = guide_legend(override.aes = list(size = 0.1)))+
scale_fill_grey(start = 0.4, end = 1 )
