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

  • Home
  • SEARCH
  • 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 7873653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:34:41+00:00 2026-06-03T02:34:41+00:00

Here is my data and plot nmar <- seq (1, 100, 5) position= rep(nmar,

  • 0

Here is my data and plot

nmar <- seq (1, 100, 5)
position= rep(nmar, 5)
n = length (nmar )
chr = rep(1:5, each = n )

mapdata <- data.frame (chr, position, 
 snpname = paste("SNP-", 1:length (position), sep = ""))
mapdata


chr.lab = 1 ; mbar.col = "blue"
layout(matrix(c(1,1,2),nc=1)) # works for two but I need to extend it to 
       n (which is level of chr = 5)

# plot level 1
mapdata1 <- mapdata[mapdata$chr == 1,]
m <- par()$mar
m[1] <- m[3] <- 0
par(mar=m)
# Set the limits of the  plot
plot(mapdata1$position,mapdata1$position-mapdata1$position, type="n",
   axes=FALSE, 
xlab="", ylab="Chromsome", yaxt="n" )

polygon(
  c(0,max(mapdata1$position + 0.08 * max(mapdata1$position)),max(mapdata1$position)+
     0.08 * max(mapdata1$position),0),
  .2*c(-0.3,-0.3,0.3,0.3),
  col= mbar.col
)
segments(mapdata1$position, -.3, mapdata1$position, .3 )
text(mapdata1$position, -.7, mapdata1$snpname, srt = 90, cex.lab = chr.lab)
text(mapdata1$position,  .7, mapdata1$position,cex.lab = chr.lab )
text(0, labels = c("Chr 2"))

Second level

# plot level 2
mapdata2 <- mapdata[mapdata$chr == 2,]
m <- par()$mar
m[1] <- m[3] <- 0
par(mar=m)
# Set the limits of the  plot
plot(mapdata2$position,mapdata2$position-mapdata1$position, type="n", axes=FALSE, 
xlab="", ylab="Chromsome", yaxt="n" )

polygon(
  c(0,max(mapdata2$position + 0.08 * max(mapdata2$position)),max(mapdata2$position)+  
 0.08 * max(mapdata2$position),0),
  .2*c(-0.3,-0.3,0.3,0.3),
  col= mbar.col
)
segments(mapdata2$position, -.3, mapdata2$position, .3 )
text(mapdata2$position, -.7, mapdata2$snpname, srt = 90, cex.lab = chr.lab)
text(mapdata2$position,  .7, mapdata2$position,cex.lab = chr.lab )
text(0, labels = c("Chr 2"))

Output
enter image description here

(1) How can I automate the process for n levels – extending similar plot to n levels of chr
(2) If you see the barsize with same specification has changed, may be due to different plot area. How can I adjust it so make all plots identical?

  • 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-03T02:34:42+00:00Added an answer on June 3, 2026 at 2:34 am

    ggplot is definitely the way to go here. But if you really want to stick with base plot, then this function would work:

    plot.as.stack= function(mapdata1, mbar.col = "blue"){
        # mapdata1 <- mapdata[mapdata$chr == chr,]
        m <- par()$mar
        m[1] <- m[3] <- 0
        par(mar=m)
        # Set the limits of the  plot
        plot(mapdata1$position,mapdata1$position-mapdata1$position, type="n",
           axes=FALSE, 
        xlab="", ylab="Chromsome", yaxt="n" )
    
        polygon(
          c(0,max(mapdata1$position + 0.08 * max(mapdata1$position)),max(mapdata1$position)+
             0.08 * max(mapdata1$position),0),
          .2*c(-0.3,-0.3,0.3,0.3),
          col= mbar.col
        )
        segments(mapdata1$position, -.3, mapdata1$position, .3 )
        text(mapdata1$position, -.7, mapdata1$snpname, srt = 90, cex.lab = chr.lab)
        text(mapdata1$position,  .7, mapdata1$position,cex.lab = chr.lab )
        text(0, labels = paste("Chr",unique(mapdata1$chr)))
    }
    
    # Example Run.
    par(mfrow=c(length(unique(mapdata$chr)),1))
    x=by(mapdata,factor(mapdata$chr),plot.as.stack) # Assigned to x to prevent output
    par(mfrow=c(1,1))
    

    As you can see, I just took your code, put it into a function, and then ran by on it. Note that this would run the function on all of the levels of chr. You could modify it so that the function takes the value of chr instead:

    plot.as.stack = function(chr){
        mapdata1 <- mapdata[mapdata$chr == chr,]
        ...
    }
    

    And then run the function with values of chr:

    par(mfrow=c(5,1))
    sapply(1:5,plot.as.stack)
    par(mfrow=c(1,1))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my plot dat <- data.frame( pos = c(1, 3, 5, 8, 10,
Here is some example data: data = data.frame(series = c(1a, 1b, 1e), reading =
I got following data frame (simplified here): H2475 H2481 H2669 H2843 H2872 H2873 H2881
Here is data. X <- 1:10 Y <- rnorm (length(X), 5, 2) ticks <-
Data: Here is sample table(TableA) data ID StartTime EndTime 1 2012-03-22 06:00:00.000 2012-03-22 06:30:00.000
I am sending HTTP GET request and receiving data here: ssize_t numBytes = recvfrom(sock,
I'm learning assembly and I have a very basic loop here segment .data msg:
My html is like this <div id=rsContainer> <table id=rsTable><!-- DATA HERE --></table> </div> and
Here is my data structure alt text http://luvboy.co.cc/images/db.JPG when i try this sql select
Here is sample data <table class=sparql border=1> <tr> <th>abstract</th></tr> <tr> <td> Cologne is Germany&#39;s

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.