【发布时间】:2015-04-18 23:23:47
【问题描述】:
在 R 中,我正在尝试根据存储的函数绘制多个图表(我对使用 R 进行编程非常陌生,所以这可能并不完全有意义)。基本上,我创建了一些图表并将它们存储在一个可以轻松使用新数据运行的函数中。我想保留该功能,同时添加在一次渲染中渲染多个图表的能力。我希望它以这样的方式结束http://www.statmethods.net/advgraphs/images/layout1.jpg
我已经运行了下面的代码,但它只是生成了每个图形的多个实例(或用新的渲染替换每个图形)。
所以我的问题是:我做错了什么?有谁知道我如何使用以下代码和函数生成四个图表以放置在一个视图中(如上面的链接)?非常感谢任何帮助。
注意:第二段代码有两个兄弟。我还有一个饼图我没有包含,但是在下面的代码中提到了。
这是我一直在使用的代码:
attach(ES)
par=(mfrow=c(2,2))
plot=(mapFunctionRead())
plot=(mapFunctionSkim())
plot=(mapFunctionDelete())
plot=(pieChart())
这是一个示例函数:
mapFunctionRead<-function(){
# draw world map
map(database="world", bg="#d4d5d1", fill = TRUE, col="#ffffff",myborder = 0)
################# For Read ####################
# Draw circles
symbols(mtReadLong, mtReadLat, circles=rep(1, length(mtReadLong)), inches=0.005, add=TRUE)
# assign numerical value that's based on the amount of time read
radiusRead<-sqrt(mtReadSec/pi)
# draw circles with fill and border
symbols(mtReadLong, mtReadLat, bg="#4173a5", fg="#5589c7", lwd=0.5, circles=radiusRead, inches=0.05, add=TRUE)
}
################# Displays data on world map for SKIM ######################
mapFunctionSkim<-function(){
# draw world map
map(database="world", bg="#d4d5d1", fill = TRUE, col="#ffffff",myborder = 0)
################# For Skim ####################
# Draw circles
symbols(mtSkimLong, mtSkimLat, circles=rep(1, length(mtSkimLong)), inches=0.005, add=TRUE)
# assign numerical value that's based on the amount of time read
radiusSkim<-sqrt(mtSkimSec/pi)
# draw circles with fill and border
symbols(mtSkimLong, mtSkimLat, bg="#ead57d", fg="#ead57d", lwd=0.5, circles=radiusSkim, inches=0.05, add=TRUE)
}
################# Displays data on world map for DELETE ######################
mapFunctionDelete<-function(){
# draw world map
map(database="world", bg="#d4d5d1", fill = TRUE, col="#ffffff",myborder = 0)
################# For Delete ####################
# Draw circles
symbols(mtDeleteLong, mtDeleteLat, circles=rep(1, length(mtDeleteLong)), inches=0.005, add=TRUE)
# assign numerical value that's based on the amount of time read
radiusDelete<-sqrt(mtDeleteSec/pi)
# draw circles with fill and border
symbols(mtDeleteLong, mtDeleteLat, bg="#77223c", fg="#9c1b3e", lwd=0.5, circles=radiusDelete, inches=0.05, add=TRUE)
}
【问题讨论】:
-
那么您的问题到底是什么?
-
很抱歉。我已经用一个实际问题更新了我的原始问题。我在上面粘贴的代码不起作用 - 图表已呈现,但它们正在堆叠。我想将它们全部呈现在一个页面上,每行两行。我一直在努力,但我添加或替换的每一段代码都只是在我的渲染中产生了问题。所以我的问题是我做错了什么,如何用上面的代码生成四个图表。第二段中的 map 函数有两个兄弟。还有一个饼图。
-
什么是 mapFunctionskim 或 mapFunctionDelete。根据您提供的内容,这些功能不存在。
-
@miles2know 嘿,我已经添加了其他两个函数。它们基本上只是调用其他信息的相同函数。我还没有把它细化为一个函数——就像我说的,我是 R 的新手,我不确定你如何在其中构建这样的函数。感谢您提供的任何帮助。
-
你认为 mtReadLong() 是函数还是变量?
标签: r function charts statistics rstudio