Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:29:19+00:00 2026-06-06T22:29:19+00:00

I’m having data as like below. I need to plot graph based on region.

  • 0

Graph in which I gotI’m having data as like below. I need to plot graph based on region. If we extract based on region, each list is not having same number of elements.

    avg_data

    date    region  AveElapsedTime
    5/1/2012        Beta    22
    5/2/2012        Beta    34
    5/3/2012        Beta    22
    5/4/2012        Beta    44
    5/5/2012        Beta    21
    5/6/2012        Beta    65
    5/7/2012        Beta    23
    5/8/2012        Beta    26
    5/9/2012        Beta    75
    5/10/2012       Beta    32
    5/3/2012        preprod 23
    5/4/2012        preprod 32
    5/5/2012        preprod 54
    5/6/2012        preprod 45
    5/7/2012        preprod 67
    5/8/2012        preprod 33
    5/10/2012       preprod 56
    5/5/2012        prod    44
    5/6/2012        prod    50
    5/7/2012        prod    30
    5/8/2012        prod    40
    5/9/2012        prod    76

To read conviniently, pasted in table format

    Date    Beta    preprod prod
    5/1/2012        22
    5/2/2012        34
    5/3/2012        22      23
    5/4/2012        44      32
    5/5/2012        21      54      44
    5/6/2012        65      45      50
    5/7/2012        23      67      30
    5/8/2012        26      33      40
    5/9/2012        75              76
    5/10/2012       32      56

This is my R script

    avg_data <- read.table("qes.tbl", header=T, sep=",")
    avg_data
            dl <- avg_data[avg_data$region == "prod", "AveElapsedTime"]
    dl
            datel <- avg_data[avg_data$region == "prod", "date"]
    datel
    #Creating the graph pdf in the below path to give as a link in the mail
    FL <- 20120631
    file <- paste("graph", FL, "pdf", sep=".")
    plot_colors <- c("blue","red","forestgreen","black")
    pdf(file, height=4.5, width=9.5, onefile=TRUE)
    graphplot <- function(l, REG, tl, num) {
            dl <- REG[REG$region == l, tl]
            datel <- REG[REG$region == l, "date"]
            lines(datel, dl, type="l", pch=2, col=plot_colors[num])
    }
    drawGraph <- function(ab, y, z, s) {
            #Creating X axis
            x <- ab[ab$region == "Beta", z]
            y <- ab[ab$region == "Beta", "date"]
            a <- x
            g_range <- range(0,x[!is.na(x)])
            x[x==0] <- NA
            plot(which(!is.na(x)),x[!is.na(x)], type="l", col="orange", ylim=g_range,axes=FALSE, ann=FALSE)
            num=0
            sapply(unique(ab$region[ab$region != "Beta"]), FUN=graphplot, REG=ab, tl=z, num=num+1)
            x <- a
            box()
            axis(1, at=1:length(x), lab=FALSE)
            text(1:length(x), par("usr")[3] - 2, srt=45, adj=1.2, labels=y, xpd=T, cex=0.3)
            scale <- s
            axis(2, las=1, at=scale*0:g_range[2], cex.axis=0.3)
            main_title<-as.expression(z)
            #Caculationg Mean, Upper limit and lower limit using the below commands
            MEANLIMIT <- seq(length=length(x), from=mean(x), by=0)
            ULIMIT <- seq(length=length(x), from=mean(x) + 2.66*sum(abs(diff(x)))/length(x), by=0)
            LLIMIT <- seq(length=length(x), from=mean(x) - 2.66*sum(abs(diff(x)))/length(x), by=0)
            lines(MEANLIMIT, type="l", col="black")
            lines(ULIMIT, type="l", pch=2, lty=2, col="grey")
            lines(LLIMIT, type="l", pch=2, lty=2, col="black")
            title(main=main_title, col.main="red", font.main=4)
            title(xlab="Test Execution Date", col.lab=rgb(0,0.5,0))
            title(ylab="Millisecond", col.lab=rgb(0,0.5,0))
            legend("topright", g_range[2], main_title, cex=0.4, col=c("blue"), lty=1);
    }
    lab<-as.character(avg_data$date)

    AET <- avg_data$AveElapsedTime
    MTitle <- "AveElapsedTime"
    #Creating graph for Average Elapsed time
            drawGraph(avg_data, lab, MTitle, 5)

My graph is not coming correctly when I try to graph using “lines” in sapply. without sapply also it is not working. It is drawing from the next x axis point. Ex: prod date is starting 5/5/2012. But in the graph, for prod, the line is starting from 5/6/2012. Likewise for preprod also.

Also Please advise how to give multiple color for the extra lines when I called through sapply ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:29:23+00:00Added an answer on June 6, 2026 at 10:29 pm

    Use ggplot and save yourself a lot of trouble:

    library(ggplot2)
    avg_data$date <- as.Date(avg_data$date, format="%m/%d/%Y")
    
    ggplot(avg_data, aes(date, AveElapsedTime)) + geom_line(aes(col=region))
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6
I have two tables with like below codes: Table: Accounts id | username |
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.