Note that there are some explanatory texts on larger screens.

plurals
  1. POscaled horizontal and vertical line/ ticks graph (map) using r
    text
    copied!<p>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).</p> <pre><code>grp &lt;- c( 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,2, 2, 2,2, 2, 2, 2, 2) sgrp &lt;- c("A", "A", "A", "A", "A", "B", "B", "B", "B" , "A", "A", "A", "A", "B", "B", "B", "B", "B") pos &lt;- 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 &lt;- 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 </code></pre> <p>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 ? </p> <p>The resulting graph should something look like:</p> <p><img src="https://i.stack.imgur.com/3Hxi4.jpg" alt="enter image description here"></p> <p>Edits: Here is small trick I could do, but not achieved (not close) what I want to:</p> <pre><code>dgp &lt;- 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 &lt;- grp + dgp plot(mydf$pos, mydf$dumv, pch = "+", ylab = "groups", xlab = "pos") </code></pre> <p><img src="https://i.stack.imgur.com/dK5gp.jpg" alt="enter image description here"></p> <p><strong>Update again:</strong>, got some idea but problems exists: </p> <pre><code>require(ggplot2) grp &lt;- c( 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,2, 2, 2,2, 2, 2, 2, 2) sgrp &lt;- c("A", "A", "A", "A", "A", "B", "B", "B", "B" , "A", "A", "A", "A", "B", "B", "B", "B", "B") position &lt;- 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 &lt;- data.frame (grp, sgrp, pos) dgp &lt;- 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 &lt;- c(0.25) mydf$group &lt;- 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)) </code></pre> <p>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. </p> <p>(2) In real data, I will have more than two groups, can I automte calculation of dgp. </p> <p><img src="https://i.stack.imgur.com/b8ZHQ.jpg" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload