ggplot
的橫坐標(biāo)軸標(biāo)簽可以傾斜征唬,不做贅述:
axis.text.x = element_text(angle = 45,vjust = 0.5,hjust = 0.5)
但是!吠式!不好看陡厘!45°的傾斜的角度有點(diǎn)過(guò)頭,位置上text和sticks離得太遠(yuǎn)特占。
就像這樣糙置,不好看
經(jīng)過(guò)調(diào)整和摸索,傾斜角度和位置調(diào)成這樣更好看些:
axis.text.x = element_text(angle = 30,vjust = 0.85,hjust = 0.75)
像這樣是目,好看
完整代碼如下:
library(ggplot2)
p1 <- ggplot(data1_SE,aes(x = addin,y = Ratio))+
geom_bar(stat="identity",width = 0.6,fill = "red")+
geom_errorbar(data = data1_SE,aes(ymin = Ratio - se, ymax = Ratio + se),width = 0.2,size = 1.5)+
geom_point(data = data1,aes(x = addin,y = Ratio),stat="identity",size = 3,alpha=0.5)+
theme(panel.background = element_blank(),
panel.grid = element_blank(),
axis.line = element_line(colour = "#000000",size = 2),
axis.text = element_text(colour = "#000000" ,size = 27),
axis.text.x = element_text(angle = 30,vjust = 0.85,hjust = 0.75), ##就是這里
axis.ticks = element_line(colour = "#000000" ,size = 2) ,
axis.ticks.length = unit(2,'mm'),
plot.margin = unit(c(0.5,0,0,0),"cm"),
axis.title.y = element_text(size = 27),
axis.title.x = element_blank(),
plot.title = element_text(hjust = 0.5),
legend.position = "none")+
scale_y_continuous(limits = c(0,100),breaks = seq(0,100,20),expand = c(0, 0))+
scale_x_discrete(labels = c("1.34e+7","6.70e+7","3.35e+8"))+
ylab("Ratio(%)")
p1
——這一part不算干貨谤饭,主要為自己方便查詢