我使用ggplot2和geom_bar生成条形图。
然后,当使用ggexport (或pdf)将其导出为pdf时,字符串的每个字符都堆叠在一起;图形在Rstudio预览窗口中看起来很好。
在前面的图表中,我已经在geom_lines中使用了ggexport,它做得很好。
有没有人能帮我一下?在此之前谢谢。
#define font
font="Arial"
#define general atributs of graphs
axisTitle=element_text(size=10, family = font, face = "bold")
axisText=element_text(size=10, family = font)
theme1= theme(
axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5, size = 10, family = font),
axis.text.y = axisText,
axis.title.x = element_blank(),
axis.title.y = axisTitle,
axis.line.x = element_line(size=0.1),
axis.line.y = element_line(size=0.1),
axis.ticks.x = element_line(size=0.1),
axis.ticks.y = element_line(size=0.1),
plot.margin = unit(c(0.5,0.5,0.5,0), "cm"))#top, right, bottom,left
graf2<-ggplot(data = subset(mBdata, subset = (Measurements == "1_1_x_4" | Measurements == "1_2_x_4") ), aes(x=reorder(VarUnit, -averages), y=averages)) +
geom_bar(aes(fill = Measurements),stat="identity", position="dodge", color="black")+
coord_cartesian(ylim = c(1,1e7))+
scale_y_log10(expand = expand_scale(mult = 0, add = 0))+
ylab("Averages over cycle") +
scale_fill_manual(values=c(color1,color2), labels=c("B30","B00"),name=NULL)+
theme(legend.position=c(0.10, 0.90),
legend.direction = "horizontal",
legend.text = element_text(size=8, family = font))+
annotate("text", label = "cycle1", x= "work [kWh]", y = 1e7*0.5, color = color1, size = 4, family = font, hjust = 0, vjust=0)+
theme1
fname="test"
ggexport(graf2,filename = paste(fname,"pdf",sep = "."),
width = 7.27,
height = 9.5/2)


下面是使用dput(head(MBdata))的数据:
structure(list(VarUnit = c("VIA_CO [ppm]", "FID_HC [ppm]", "CLD700_NOx [ppm]",
"CPC_PN [#/cm3]", "FTIR_CO [ppm]", "FTIR_NOX [ppm]"), Measurements = structure(c(1L,
1L, 1L, 1L, 1L, 1L), .Label = c("1_1_x_4", "2_1_x_4", "1_2_x_4",
"2_2_x_4", "1_1_x_5", "2_1_x_5", "1_2_x_5", "2_2_x_5"), class = "factor"),
averages = c(0.0851193781232649, 2.01203081621322, 217.02611049417,
640967.527383398, 0.737018707801222, 225.867359490006)), row.names = c(NA,
6L), class = "data.frame")发布于 2019-08-14 18:20:25
无需更改警察,它就可以工作;更改警察并使用Cair_pdf (来自grDevices)也是有效的。
https://stackoverflow.com/questions/57478003
复制相似问题