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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:47:03+00:00 2026-06-07T03:47:03+00:00

Here is small example I want to plot (2 group and 2 subgroup, just

  • 0

Here is small example I want to plot (2 group and 2 subgroup, just for simplicity, however I might have n group and k subgroups).

grp <- c(  1,   1,   1,  1, 1,  1, 1, 1, 1,  2,2, 2, 2,2, 2, 2, 2, 2)
sgrp <- c("A", "A", "A", "A", "A",  "B", "B", "B", "B" ,  "A", "A", "A", "A",
  "B", "B", "B", "B", "B")
pos <- c(1.1, 2.1, 3.2, 4.1, 5.0,1.1, 2.0, 5.0, 6.2,1.0, 3.0, 4.1, 5.0,1.0,
 2.1, 3.01, 4.0, 5.02)
mydf <- data.frame (grp, sgrp, pos)
   grp sgrp  pos
1    1    A 1.10
2    1    A 2.10
3    1    A 3.20
4    1    A 4.10
5    1    A 5.00
6    1    B 1.10
7    1    B 2.00
8    1    B 5.00
9    1    B 6.20
10   2    A 1.00
11   2    A 3.00
12   2    A 4.10
13   2    A 5.00
14   2    B 1.00
15   2    B 2.10
16   2    B 3.01
17   2    B 4.00
18   2    B 5.02

Pos determines where ticks need to be in x axis. The central line (long line) starts from zero and ends at maximum position of grp + 1. Is is possible to make such graph ?

The resulting graph should something look like:

enter image description here

Edits:
Here is small trick I could do, but not achieved (not close) what I want to:

dgp <- c(0, 0, 0, 0, 0,  0.15, 0.15,0.15, 0.15 ,  0, 0, 0, 0,  
0.15, 0.15, 0.15, 0.15, 0.15)
mydf$dumv <- grp + dgp
plot(mydf$pos, mydf$dumv, pch = "+", ylab = "groups", xlab = "pos")

enter image description here

Update again:, got some idea but problems exists:

require(ggplot2)

grp <- c(  1,   1,   1,  1, 1,  1, 1, 1, 1,  2,2, 2, 2,2, 2, 2, 2, 2)
sgrp <- c("A", "A", "A", "A", "A",  "B", "B", "B", "B" ,  "A", "A", "A", "A",
  "B", "B", "B", "B", "B")
position <- c(1.1, 2.1, 3.2, 4.1, 5.0,1.1, 2.0, 5.0, 6.2,1.0, 3.0, 4.1, 5.0,1.0,
 2.1, 3.01, 4.0, 5.02)
mydf <- data.frame (grp, sgrp, pos)
dgp <- c(0, 0, 0, 0, 0,  0.15, 0.15,0.15, 0.15 ,  0, 0, 0, 0,
0.15, 0.15, 0.15, 0.15, 0.15)
mydf$barheight <- c(0.25)
mydf$group <- grp + dgp

ggplot(mydf) +
  geom_line(aes(position, factor(group), group = factor(group)),
            size = 2, colour = "purple") +
  geom_rect(aes(y = factor(group),
                xmin = position - 0.02,
                xmax = position + 0.02,
                ymin = group - barheight/2,
                ymax = group + barheight/2))

Problem: ….
(1) I can not make group non factor, the postion of rectangle are in wrong place, I want to put A, B next to each other while gap between 1 and 2.

(2) In real data, I will have more than two groups, can I automte calculation of dgp.

enter image description here

  • 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-07T03:47:04+00:00Added an answer on June 7, 2026 at 3:47 am
     plot(NULL, ylim=c(0,4), xlim=range(mydf$pos))
     abline(h=1:4 ,col=1:2 )
     with(mydf, segments(x0=pos, y0=as.numeric(interaction(mydf$grp, mydf$sgrp))-.2, 
                         y1=as.numeric(interaction(mydf$grp, mydf$sgrp))+.2,
                         col= mydf$grp, lty=as.numeric(mydf$sgrp)) )
    

    (I’m not yet a ggplot user, so this is base graphics. You can tweak the ylim and add a ylab argument to properly label. You may want to also use yaxt="n" and axis() to label your groups and subgroups.)
    enter image description here

    Here’s an alternate setup using the interaction values to pick from a vector of vertical locations.

     plot(NULL, ylim=c(0.5,4.5), xlim=range(mydf$pos))
     with(mydf, segments(x0=pos, 
                 y0=c(1.3,1.7,3.3,3.7)[as.numeric(interaction(mydf$grp, mydf$sgrp))]-.1, 
                 y1=c(1.3,1.7,3.3,3.7)[as.numeric(interaction(mydf$grp, mydf$sgrp))]+.1, 
                 col= mydf$sgrp, lty=as.numeric(mydf$grp)) )
    abline(h=c(1.3,1.7,3.3,3.7) ,col= rep(1:2, each=2), lty=1:2,lwd=3)
    

    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 am trying to make a small thread example. I want to have a
Here is a small example to illustrate my data: > df <- data.frame(subgroup=rep(paste(s,1:3, sep=),
Here is just small example of my problem: myfun <- function (dataframe) { namef
Here is just small example (not exactly, but similar issue) I am trying to
i have a small problem here which i cannot fix,This post goes through but
I want to do formatting using echo in shell scripting. Here is a small
Here's the problem -- I have a few thousand small text snippets, anywhere from
I have a small codeigniter controller. Below is the code class Example extends CI_Controller
I've just started using google charts and want to use it in a small
I have made a small example in order to understand how boost::bind () works

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.