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 8263869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:15:05+00:00 2026-06-08T04:15:05+00:00

I have some sequence feature information I want to visualize. Here is some toy

  • 0

I have some sequence feature information I want to visualize.
Here is some toy data(the specific r code to regenerate the data is at the end)

          type index variable position
...
14         CDS    14    start 31129
15        exon    15    start 32196
16         CDS    16    start 32196
17  stop_codon    17    start 32247
18        exon     1      end 12166
19         CDS     2      end 12166
...

The command I used to generate the following plot is

qplot(position,type,data=m2data,color=type)+xlim(11950,15000)

what I have so far

But I want to add the line segments between “start” and “end” that share the same “index”
like following, which I made with the paint.

What I want

How can I achieve this with ggplot2 in R?

The following is the data

m2data<-structure(list(type = structure(c(2L, 1L, 3L, 2L, 1L, 2L, 1L, 
4L, 2L, 2L, 1L, 3L, 2L, 1L, 2L, 1L, 4L, 2L, 1L, 3L, 2L, 1L, 2L, 
1L, 4L, 2L, 2L, 1L, 3L, 2L, 1L, 2L, 1L, 4L), class = "factor", .Label = c("CDS", 
"exon", "start_codon", "stop_codon")), index = c("1", "2", "3", 
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", 
"16", "17", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", 
"11", "12", "13", "14", "15", "16", "17"), variable = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L), .Label = c("start", "end"), class = "factor"), position= c(11955L, 
12026L, 12026L, 16677L, 16677L, 17745L, 17745L, 17787L, 18309L, 
28587L, 28658L, 28658L, 31129L, 31129L, 32196L, 32196L, 32247L, 
12166L, 12166L, 12028L, 16841L, 16841L, 17814L, 17786L, 17789L, 
18898L, 28798L, 28798L, 28660L, 31299L, 31299L, 32270L, 32246L, 
32249L)), .Names = c("type", "index", "variable", "position"), row.names = c(NA, 
-34L), class = "data.frame")
  • 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-08T04:15:07+00:00Added an answer on June 8, 2026 at 4:15 am

    Here is a solution to your problem. Although your question is quite similar to a previous one, I think that providing an answer specific to your data set is still useful.

    library(ggplot2)
    library(reshape2)
    
    # Use dcast (in reshape2 package) to create separate columns for start and end.
    dat = dcast(m2data, type + index ~ variable, value.var="position")
    
    plot_1 = ggplot(dat, aes(x=start, xend=end, y=type, yend=type, colour=type)) +
             geom_segment(size=3) +
             geom_point(size=3) +
             geom_point(aes(x=end), size=3)
    
    ggsave(filename="plot_1.png", plot_1, width=10, height=2.5)
    

    enter image description here

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

Sidebar

Related Questions

I have some code: @Id @SequenceGenerator(name = SOMETHING_SEQ) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = SOMETHING_SEQ)
I have some arbitrary pixel data that I want to save as a PNG.
I have some code that will change the background color of a specific label
Suppose I have some schema: <xsd:schema ...> <xsd:element name=foo> <xsd:complexType> <xsd:sequence> <xsd:element name=fooElement type=xs:string
I have some old code (pre Java 1.5) that uses classes to implement type
I have some code which is the same except that a certain sequence of
I have some types with a sequence inside, which does restrict the order of
I have some data loaded as a np.ndarray and need to convert it to
I have some code on two systems running kernel 2.4.20 and kernel 2.4.38 .
I have a gb file and I need to extract some specific features from

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.