没有双y轴
时的图片
输入的Fig3_C_RF_SOSA.xlsx数据类型是这样的
library(openxlsx)
library(reshape2)
library(ggplot2)
databar=reaRd.xlsx('D:/FDU/data/Fig3_C_RF_SOSA.xlsx')
df <- melt(databar)
colnames(df)[1] <- 'Methods'
df$Methods<- factor(df$Methods,levels =c("SOSA Model","RF Model"))
library(ggsci)
geom_bar(stat="identity",position=position_dodge(0.75))
q1<-ggplot(data=df, mapping=aes(x = variable, y = value,fill=Methods))+
geom_bar(colour="black",stat="identity",position=position_dodge(0.9)) +
scale_fill_manual(values = c("#E41A1C", "#377EB8")) +
theme_bw()+
theme(panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
text=element_text(size = 18,face = 'bold'),
axis.text.y= element_text(size=13,colour = 'black'), # 设置y轴的数字大小
axis.text.x = element_text(size=13,angle = 45,hjust = 1,colour = 'black'))+labs(x='',y='Importance of SOSA Model features')+theme(text=element_text(size=18, color ='black'))
##### 只需增加下边这一行就行啦####
q1 <- q1 + scale_y_continuous(sec.axis = sec_axis(~. /20, name = "Importance of RF Model features"))
##########
ggsave(file='./fig3.png',width = 270,height= 150,units = 'mm')