Why is ggplot not plotting multiple windows in R?

感情迁移 提交于 2019-12-25 04:19:33

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8188375/why-is-ggplot-not-plotting-multiple-windows-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!