首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >生成pdf时出现奇怪的字符串

生成pdf时出现奇怪的字符串
EN

Stack Overflow用户
提问于 2019-08-13 20:45:09
回答 1查看 95关注 0票数 0

我使用ggplot2和geom_bar生成条形图。

然后,当使用ggexport (或pdf)将其导出为pdf时,字符串的每个字符都堆叠在一起;图形在Rstudio预览窗口中看起来很好。

在前面的图表中,我已经在geom_lines中使用了ggexport,它做得很好。

有没有人能帮我一下?在此之前谢谢。

代码语言:javascript
运行
复制
  #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))的数据:

代码语言:javascript
运行
复制
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")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-14 18:20:25

无需更改警察,它就可以工作;更改警察并使用Cair_pdf (来自grDevices)也是有效的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57478003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档