Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To create a data.frame, you can do it crudely like this:</p> <pre><code>df &lt;- data.frame(values=unlist(FHM_CS, use.names=FALSE), tag=rep(names(FHM_CS), times=sapply(FHM_CS, length)) </code></pre> <p>But for usage with <code>ggplot2</code>, we should merge everything into a single dataframe:</p> <pre><code>df.CS &lt;- data.frame(values=unlist(FHM_CS, use.names=FALSE), tag=rep(names(FHM_CS), times=sapply(FHM_CS, length)), class='CS', stringsAsFactors=TRUE) df.CD &lt;- data.frame(values=unlist(FHM_CD, use.names=FALSE), tag=rep(names(FHM_CD), times=sapply(FHM_CD, length)), class='CD', stringsAsFactors=TRUE) my.data &lt;- rbind(df.CS, df.CD) </code></pre> <p><strong>Edit</strong> Alternatively, as seen what Michele found, use <code>melt</code>:</p> <pre><code>library(reshape2) df.CD &lt;- data.frame(melt(FHM_CD), class='CD') df.CS &lt;- data.frame(melt(FHM_CS), class='CS') ## Except now, instead of `tag`, we have `L1`. my.data &lt;- rbind(df.CD, df.CS) my.data$tag &lt;- my.data$L1 </code></pre> <p><strong>End of edit</strong></p> <p>Then to plot, as you want (I was lazy and didn't enter much data):</p> <pre><code>library(ggplot2) ggplot(my.data, aes(x=interaction(tag, class), y=values)) + geom_point(position=position_jitter()) </code></pre> <p><img src="https://i.stack.imgur.com/YJC73.png" alt="enter image description here"></p> <p>But lets try to add the horizontal bars. But, I would use facetting so we will get the following:</p> <pre><code>ggplot(my.data, aes(x=tag, y=values)) + geom_point(position=position_jitter()) + stat_summary(fun.y='mean', geom='errorbarh', aes(xmin=as.integer(tag)-0.3, xmax=as.integer(tag)+0.3), height=0) + facet_grid(.~class) </code></pre> <p><img src="https://i.stack.imgur.com/WqL2s.png" alt="enter image description here"></p> <p><strong>Edit 2</strong></p> <p>First manually create the interaction vector:</p> <pre><code>my.data$it &lt;- with(my.data, interaction(tag, class, sep=' - ', lex.order=TRUE)) </code></pre> <p>Then we plot as previously.</p> <pre><code>ggplot(my.data, aes(x=it, y=values)) + geom_point(position=position_jitter()) + stat_summary(fun.y='mean', geom='errorbarh', aes(xmin=as.integer(it)-0.3, xmax=as.integer(it)+0.3, height=0, colour=class)) </code></pre> <p><img src="https://i.stack.imgur.com/FYSFX.png" alt="enter image description here"></p> <p>Of course, you might want to edit the arguments to <code>position_jitter()</code> to squeeze the points more closer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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