An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111113/8108d312/attachment.pl>
dev.new() within a loop
4 messages · David Winsemius, Giovanni Azua
On Nov 12, 2011, at 6:04 PM, Giovanni Azua wrote:
Hello, I have a loop where I iterate performance data files within a folder, parse and plot them in one shot (see below). However, when executing plot_raw which invokes dev.new(..) all windows come out blank whereas if I execute each file outside of a loop then I can see the plots properly.
Perhaps ...(you did not say what package this plot_raw function comes from) ... Read the FAQ about why lattice plot don't print. (It applies to all grid based plotting functions.)
David
> What's wrong here?
>
> Thanks in advance,
> Best regards,
> Giovanni
>
> # given a directory name, it will iterate all files that match the
> given pattern
> #basedir <- "/Users/bravegag/code/asl11/data/2k-r1-
> test-20111111_data/"
> basedir <- "/Users/bravegag/code/asl11/data/
> nclients_2_128-20111110_data/"
> pattern <- paste("logs.*cl\\-.*mw\\-.*db\\-.*\\-client\\.dat",sep="")
> all_files <- dir(path=basedir, pattern=pattern)
>
> throughput <- NULL
> response <- NULL
>
> #file_name <- all_files[1]
>
> # iterate all files
> for (file_name in all_files) {
> print(paste("processing", file_name, "..."))
>
> df <- read.table(paste(basedir, file_name, sep="")) #
> read the data as a data frame
> names(df)[names(df)=="V1"] <- "Time"
> names(df)[names(df)=="V2"] <- "Partitioning"
> names(df)[names(df)=="V3"] <- "Workload"
> names(df)[names(df)=="V4"] <- "Runtime"
>
> # get rid of first and last n minutes
> df <- subset(df, df$Time > warmup_cooldown_minutes)
> df <- subset(df, df$Time < (max(df$Time) - warmup_cooldown_minutes))
>
> #
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> # Throughput
> #
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> if (decouple) {
> dft <- aggregate(x=df$Runtime, by=list(df$Time,df$Workload),
> FUN=length)
> names(dft)[names(dft)=="Group.1"] <- "Time"
> names(dft)[names(dft)=="Group.2"] <- "Workload"
> names(dft)[names(dft)=="x"] <- "Y"
>
> } else {
> dft <- aggregate(x=df$Runtime, by=list(df$Time), FUN=length)
> names(dft)[names(dft)=="Group.1"] <- "Time"
> names(dft)[names(dft)=="x"] <- "Y"
> }
> dft$se <- 0
> plot_raw(dft,connect=TRUE,label=file_name)
> }
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111113/6b681586/attachment.pl>
In a private communication this poster has indicated that he eventually found the answer by Googling the question. (The solution was as described in the FAQ.)
David.
On Nov 13, 2011, at 5:21 AM, Giovanni Azua wrote:
> Hello David,
>
> On Nov 13, 2011, at 5:20 AM, David Winsemius wrote:
>>> However, when executing plot_raw which invokes dev.new(..) all
>>> windows come out blank whereas if I execute each file outside of a
>>> loop then I can see the plots properly.
>>
>> Perhaps ...(you did not say what package this plot_raw function
>> comes from) ... Read the FAQ about why lattice plot don't print.
>> (It applies to all grid based plotting functions.)
>>
> plot_raw is my own function which just calls ggplot2. So basically I
> am not using Lattice.
>
> What can I do differently to avoid the new windows coming back empty?
>
> Thanks in advance,
> Best regards,
> Giovanni
>
> plot_raw <-
> function(data,connect=TRUE,y_break=500,y_top=-1,label="") {
> dev.new()
> title <- paste(label, sep="")
> if (y_top == -1) {
> y_top <- max(data$Y)
> }
>
> if (!decouple) {
> # add fake group
> data$Workload <- 'All'
> }
>
> p <-
> ggplot
> (data,aes(x=Time,y=Y,group=Workload,shape=Workload,colour=Workload)) +
> geom_point(fill="white", size=3) +
> scale_y_continuous(breaks=seq(0,max(data$Y),y_break), limits=c(0,
> y_top)) +
> scale_y_continuous(breaks=seq(0,y_limit_top(data$Y,data$se),
> y_break_step(data$Y,data$se)),
> limits=c(0, y_limit_top(data$Y,data$se))) +
> opts(title=title) + theme_bw() +
> scale_x_continuous(breaks=data$Time, labels=as.character(data
> $Time))
>
> if (connect) {
> p + geom_line()
> } else {
> p
> }
> }
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT