3

我有这个 R 代码,它工作得很好,如果我在 R 控制台或作为 RScript 运行它,我会得到带有绘图的位图

library(DBI);
library(RMySQL);
library(brew);
library(lattice);
con <- dbConnect(MySQL(),server credentials)
x <- dbGetQuery(con,"SELECT name, distance FROM distances")
bitmap("/tmp/dist_6078.bmp")
dotplot(x$distance~x$name, col='red', xlab='name', ylab='distance', main='Distance plot')
dev.off()

问题是,如果我将 <% 和 %> 之间的所有内容括起来并使用 brew 库,我会得到一个空白图像。如果我使用基本的 R 图,一切正常,问题仅在我使用格子时。

4

1 回答 1

7

来自 R FAQ 7.22

xyplot() 等格函数创建图形对象,但不显示它(ggplot2 图形和 S-Plus 中的格状图形也是如此)。图形对象的 print() 方法产生实际的显示

工作代码

library(DBI);
library(RMySQL);
library(brew);
library(lattice);
con <- dbConnect(MySQL(),server credentials)
x <- dbGetQuery(con,"SELECT name, distance FROM distances")
bitmap("/tmp/dist_6078.bmp")
plot_obj <- dotplot(x$distance~x$name, col='red', xlab='name', ylab='distance', main='Distance plot')
print(plot_obj)
dev.off()
于 2011-11-05T16:52:08.663 回答