我想补充LaTeX排版到地块元件R(例如:标题,轴标签,注释等)的使用任一组合base/lattice或与ggplot2.
问题:
LaTeX使用这些包进入图表,如果是这样,它是如何完成的? 例如,通过这里讨论的包进行Python matplotlib编译:http://www.scipy.org/Cookbook/Matplotlib/UsingTexLaTeXtext.usetex
是否有类似的过程可以生成这样的图R?
Chr*_*ois 46
这是一个使用示例ggplot2:
q <- qplot(cty, hwy, data = mpg, colour = displ)
q + xlab(expression(beta +frac(miles, gallon)))
Run Code Online (Sandbox Code Playgroud)
替代文字http://i31.tinypic.com/10z7n7d.png
Chr*_*ois 35
从这里被盗,以下命令正确使用LaTeX绘制标题:
plot(1, main=expression(beta[1]))
Run Code Online (Sandbox Code Playgroud)
有关?plotmath详细信息,请参阅
Ste*_*ari 28
该脚本包含一个TeX将LaTeX公式近似转换为R的plotmath表达式的函数.您可以在任何可以输入数学注释的地方使用它,例如轴标签,图例标签和一般文本.
例如:
x <- seq(0, 4, length.out=100)
alpha <- 1:5
plot(x, xlim=c(0, 4), ylim=c(0, 10),
xlab='x', ylab=TeX('$\\alpha x^\\alpha$, where $\\alpha \\in 1\\ldots 5$'),
type='n', main=TeX('Using $\\LaTeX$ for plotting in base graphics!'))
invisible(sapply(alpha, function(a) lines(x, a*x^a, col=a)))
legend('topleft', legend=TeX(sprintf("$\\alpha = %d$", alpha)),
lwd=1, col=alpha)
Run Code Online (Sandbox Code Playgroud)
产生这个情节.
这是我自己的实验室报告中的内容.
tickzDevice导出tikz图像LaTeX请注意,在某些情况下,"\\"变为"\"并"$"变为"$\"以下R代码:"$z\\frac{a}{b}$" -> "$\z\frac{a}{b}$\"
xtable也将表导出到乳胶代码
代码:
library(reshape2)
library(plyr)
library(ggplot2)
library(systemfit)
library(xtable)
require(graphics)
require(tikzDevice)
setwd("~/DataFolder/")
Lab5p9 <- read.csv (file="~/DataFolder/Lab5part9.csv", comment.char="#")
AR <- subset(Lab5p9,Region == "Forward.Active")
# make sure the data names aren't already in latex format, it interferes with the ggplot ~ # tikzDecice combo
colnames(AR) <- c("$V_{BB}[V]$", "$V_{RB}[V]$" , "$V_{RC}[V]$" , "$I_B[\\mu A]$" , "IC" , "$V_{BE}[V]$" , "$V_{CE}[V]$" , "beta" , "$I_E[mA]$")
# make sure the working directory is where you want your tikz file to go
setwd("~/TexImageFolder/")
# export plot as a .tex file in the tikz format
tikz('betaplot.tex', width = 6,height = 3.5,pointsize = 12) #define plot name size and font size
#define plot margin widths
par(mar=c(3,5,3,5)) # The syntax is mar=c(bottom, left, top, right).
ggplot(AR, aes(x=IC, y=beta)) + # define data set
geom_point(colour="#000000",size=1.5) + # use points
geom_smooth(method=loess,span=2) + # use smooth
theme_bw() + # no grey background
xlab("$I_C[mA]$") + # x axis label in latex format
ylab ("$\\beta$") + # y axis label in latex format
theme(axis.title.y=element_text(angle=0)) + # rotate y axis label
theme(axis.title.x=element_text(vjust=-0.5)) + # adjust x axis label down
theme(axis.title.y=element_text(hjust=-0.5)) + # adjust y axis lable left
theme(panel.grid.major=element_line(colour="grey80", size=0.5)) +# major grid color
theme(panel.grid.minor=element_line(colour="grey95", size=0.4)) +# minor grid color
scale_x_continuous(minor_breaks=seq(0,9.5,by=0.5)) +# adjust x minor grid spacing
scale_y_continuous(minor_breaks=seq(170,185,by=0.5)) + # adjust y minor grid spacing
theme(panel.border=element_rect(colour="black",size=.75))# border color and size
dev.off() # export file and exit tikzDevice function
Run Code Online (Sandbox Code Playgroud)