晶格图在函数内部不起作用 [英] lattice plots not working inside a function

查看:50
本文介绍了晶格图在函数内部不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个R代码,可以很好地工作,并且如果我在R控制台中或以RScript的形式运行它,就会获得带有绘图的位图

I have this R code, which works perfectly and i get the bitmap with the plot if i run it in R console or as a 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图,一切都可以正常工作,只有当我使用晶格时,问题才会出现.

Issue is, i am getting a blank image if i enclose everything between <% and %> and use brew library. Everything works fine if i use basic R plots, issue is only when i use lattice.

推荐答案

来自R FAQ 7.22

From the R FAQ 7.22

诸如xyplot()之类的格函数会创建一个图形对象,但不会 显示它(ggplot2图形和网格图形也是如此 在S-Plus中).图形对象的print()方法产生 实际显示

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

这篇关于晶格图在函数内部不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆