簡體   English   中英

如何在bwplot中添加文本(R中的晶格圖形)?

[英]How can I add text in a bwplot (lattice graphics in R)?

我需要點陣bwplot的幫助。 我制作了多面板圖,並將它們放在同一窗口中。

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))

我想做的是,在每個圖的圖邊距之外包括相同的文本,第一個圖的字母A和第二個圖的字母B有助於在我的報告中調用此圖(例如,圖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))

您可能需要調整這些值才能獲得所需的展示位置

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM