当我导出绘图的pdf时,误差线不会垂直对齐。我认为这是因为我使用的形状。
数据是:
cat stdev mean_old mean_new
1 0.0214 1.5954398 1.4514398
2 0.0171 1.3915428 1.2825428
3 0.014 1.1224943 1.0731943
4 0.0187 0.8035697 0.7713697
5 0.00945 0.3998517 0.3814517
6 0.0106 0.2333042 0.2076042
代码是:
if (!require("pacman")) install.packages("pacman")
pacman::p_load(ggplot2, extrafont, scales)
font_install("fontcm")
loadfonts()
Raw_data$cat <- factor(Raw_data$cat, levels = c("1", "2", "3", "4", "5", "6"))
Plot1<-ggplot(data=Raw_data)+
geom_point(aes(x=cat,y=mean_old), stat="identity", colour = "black" , alpha=1, shape=95, size=10)+
geom_point(aes(x=cat,y=mean_new), stat="identity", colour = "red", alpha = 1, shape=95, size=10)+
geom_errorbar(aes(ymin = mean_new - stdev, ymax = mean_new + stdev, x=cat), alpha = 0.5, size=0.4, width=0.1)+
geom_text(aes(x=cat, y=mean_old, label=sprintf("%0.2f", round(mean_old, digits = 2))), vjust=-1, color='black', size=2)+
theme(panel.background = element_blank(),
axis.text.x=element_text(size=8, color="black", angle=45, vjust=0.5),
axis.text.y=element_text(size=8, color="black"),
axis.title.y=element_text(size=8),
axis.title.x=element_text(size=8),
plot.title=element_text(size=8),
panel.border = element_rect(fill = NA, colour = "black"),
strip.background = element_rect(fill="snow1"),
legend.title=element_blank(),
legend.text=element_text(size=45),
legend.key.width = unit(2, "cm"),
legend.key.height = unit(2, "cm"),
axis.ticks = element_line(size = 0.1))+
scale_x_discrete()+
ylab("Means")+
xlab("Categories")
Plot1
pdf(file.path(OutputPath, "output.pdf"), family="CM Roman", width=4, height=6)
Plot1
dev.off()
在情节窗口中看起来如何:
pdf导出中的内容: