问题描述
我可以使用此数据集来格式化图例,并在y轴上包含千位分隔符;
Data <- tibble::tribble(
~Site,~Test,~Score1,~Score2,~Score3,"A","SD",5904,9691,NA,"B",2697,4484,"A ","MB",11418,7666,2517,6445,"C","FO",9588,"FI",5423,"NF",1527
)
我使用了这段代码;
library(dplyr)
library(tidyr)
library(ggplot2)
Data %>%
pivot_longer(cols = -c(Site,Test)) %>%
mutate(Test = factor(Test,levels = c('SD','MB','FI','FO','NF'),ordered = T)) %>%
ggplot(aes(x=Site,y=value,fill=name,legend = TRUE))+
ylim(0,20000) +
ylab("Total score") +
geom_bar(stat='identity')+
facet_wrap(.~Test,scales = 'free_x',ncol = 5,strip.position = "bottom")+
theme_minimal()+
theme(strip.placement = "outside",panel.spacing = unit(0,"points"),strip.background = element_blank(),strip.background.y = element_blank(),panel.background = element_rect(fill = "white"),panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.border = element_blank(),strip.text = element_text(face = "bold",size = 9))+
scale_color_discrete(name = "Legend",label=c("Score 1","Score 2","Score 3"))
我无法正确标记图例,并在y值上使用千位分隔符。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)