如何在bwplot中添加文本(R中的格子图形)?
问题描述:
我需要帮助格子bwplot。我制作了我的多平面图,并将它们放在同一个窗口中。如何在bwplot中添加文本(R中的格子图形)?
library(lattice)
attach(mtcars)
gear.f<-factor(gear,levels=c(3,4,5), labels=c("3gears","4gears","5gears"))
cyl.f <-factor(cyl,levels=c(4,6,8), labels=c("4cyl","6cyl","8cyl"))
plot1 <- bwplot(cyl.f~mpg|gear.f, ylab="Cylinders", xlab="Miles per Gallon", main="Mileage by Cylinders and Gears", layout=(c(1,3)))
plot2 <- xyplot(mpg~wt|cyl.f*gear.f, main="Scatterplots by Cylinders and Gears", ylab="Miles per Gallon", xlab="Car Weight")
print(plot1, position=c(0, 0.5, 1, 1), more=TRUE)
print(plot2, position=c(0, 0, 1, 0.5))
我想这样做,这是对包括第一曲线和B的第二个有用的回忆在我的报告这个阴谋的情节保证金外同一文本中的每个情节,字母A(例如图。 1A和图1)。
有人有有用的建议吗?
答
格构建在网格图形。添加图形标签的最直接方式是使用grid.text
。你的两个print()
通话后,加入
library(grid)
grid.text("A", .1, .95, gp=gpar(fontsize=20))
grid.text("B", .1, .45, gp=gpar(fontsize=20))
您可能需要调整这些值来获得位置你喜欢它
太谢谢你了!现在我的情节是完美的! – user3032235 2014-09-02 12:46:16