代码之家  ›  专栏  ›  技术社区  ›  ksm001

如何在ggplot2中生成没有卷曲的卷发?

  •  2
  • ksm001  · 技术社区  · 7 年前

    在绘制图形时 ggplot ,使用 labs(x=expression(paste(lambda)) 产生以下结果:

    enter image description here

    但是,在我需要这个图的文章中,在LaTeX中写入$\lambda$会产生一个lambda,如下所示:

    enter image description here

    如你所见,他们看起来不一样。如何更改R生成的lambda,使我的lambda在文章中的每个地方都一样?

    2 回复  |  直到 7 年前
        1
  •  2
  •   Ben Bolker    7 年前

    library(tikzDevice) . 这让 完全相同的 字体等等,你在乳胶中使用的任何东西。为了获得最大的满意度/集成,可以将这些tikz文件直接嵌入到knitr/swave文件中(请参见 here , here , here

    library(ggplot2)
    library(tikzDevice)
    
    df <- data.frame(x = 1:10, y = 1:10)
    
    g <- ggplot(df) + geom_point(aes(x = x, y = y))
    g <- g + theme(axis.title.x = element_text(size = 50))
    ## dollar signs for LaTeX math mode, double-\ to make R happy
    g <- g + xlab("$\\lambda$")
    

    tikz("tikz1.tex", standAlone=TRUE)
    print(g)
    dev.off()
    

    转换为PDF(并从那里转换为PNG,这样我就可以在这里发布结果)

    system("pdflatex tikz1.tex")
    system("evince tikz1.pdf")   ## look at it with my system's PDF viewer
    system("convert tikz1.pdf tikz1.png")  ## ImageMagick
    

    enter image description here

        2
  •  1
  •   Dan    7 年前

    library(ggplot2)
    
    df <- data.frame(x = 1:10, y = 1:10)
    
    g <- ggplot(df) + geom_point(aes(x = x, y = y))
    g <- g + theme(axis.title.x = element_text(size = 50))
    g <- g + xlab("\u03BB")
    print(g)
    

    enter image description here