gpt4 book ai didi

r - 格子图在函数内部不起作用

转载 作者:行者123 更新时间:2023-12-04 11:43:42 25 4
gpt4 key购买 nike

我有这个 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 图,一切正常,只有当我使用 lattice 时才会出现问题。

最佳答案

来自 R FAQ 7.22

Lattice functions such as xyplot() create a graph object, but do not display it (the same is true of ggplot2 graphics, and Trellis graphics in S-Plus). The print() method for the graph object produces the actual display

工作代码

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

关于r - 格子图在函数内部不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7981507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com