为什么ggplot不能在R中绘制多个窗口? [英] Why is ggplot not plotting multiple windows in R?
问题描述
我遇到了一些我写的R函数的问题。我有2个绘图函数,我想写一个函数为两个函数创建图。这个函数看起来像这样
plotBoth = function(path = NULL){
plotPopulationStats(path)
plotInstructionFrequencies(path)
}
然而,只有我称之为第二个的指令才会被绘制,第一条指令只绘制一个空白窗口。下面是这些函数的简化版本。
plotInstructionFrequencies = function(path = NULL){
quartz()
table< - read.table(path,header = TRUE);
frame< - as.data.frame(table);
frame $ time = seq(1,length(table $ noop));
frame $ mean = NULL
frame $ sd = NULL
frame $ variance = NULL
Molten< - melt(frame,id.vars =time);
ggplot(Molten,aes(x = time,y = value,color = variable))+ geom_line()
}
和
plotPopulationStats =函数(path = NULL){
quartz ()
table< - read.table(path,header = TRUE);
frame< - as.data.frame(table);
frame $ time = seq(1,length(table $ noop));
frame $ noop = NULL
frame $ plus = NULL
...
frame $ store = NULL
Molten< - melt(frame,id.vars = 时间);
ggplot(Molten,aes(x = time,y = value,color = variable))+ geom_line();
}
所有函数都在单独的文件中,但我希望它们全部在一个文件中。
这两个函数在单独调用时都可以很好地显示出来。
阅读常见问题7.22:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#您需要打印()您的ggplot或格子图。
($)
$ b $ p $
I am having a problem with a couple R functions I wrote. I have 2 plotting functions and I want to write a function that creates plots for both of the functions. This function looks like this
plotBoth = function(path = NULL){
plotPopulationStats(path)
plotInstructionFrequencies(path)
}
However only whichever instruction I call second gets plotted, while the first instruction only plots a blank window. Below are simplified versions of these functions.
plotInstructionFrequencies = function(path = NULL){
quartz()
table <- read.table(path, header=TRUE);
frame <- as.data.frame(table);
frame$time = seq(1, length(table$noop));
frame$mean = NULL
frame$sd = NULL
frame$variance = NULL
Molten <- melt(frame, id.vars = "time");
ggplot(Molten, aes(x = time, y = value, colour = variable)) + geom_line()
}
and
plotPopulationStats = function(path = NULL){
quartz()
table <- read.table(path, header=TRUE);
frame <- as.data.frame(table);
frame$time = seq(1, length(table$noop));
frame$noop = NULL
frame$plus = NULL
...
frame$store = NULL
Molten <- melt(frame, id.vars = "time");
ggplot(Molten, aes(x = time, y = value, colour = variable)) + geom_line();
}
All the functions are in separate files, but I would like to have them all in one file.
Both functions plot fine when called individually.
Read Faq 7.22: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f
You need to print() your ggplot or lattice plots.
这篇关于为什么ggplot不能在R中绘制多个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!