Note that there are some explanatory texts on larger screens.

plurals
  1. POggplot does not plot data in the given order
    text
    copied!<p>I'm trying to plot some date points:</p> <pre><code>library(ggplot2) library(plyr) set.seed(1234) df &lt;- data.frame( c1 = as.character(1:10), c2 = sample(seq(from=as.Date("2012-01-01"),to=as.Date("2012-12-01"),by="day"), 10) ) df &lt;- arrange(df,c2) qplot(c2,c1,data=df) + scale_x_date(breaks="1 month") </code></pre> <p>Although I used <em>arrange</em> to sort the data, ggplot does not plot the data in order: <img src="https://i.stack.imgur.com/Egcgz.png" alt="enter image description here"></p> <p>The expected plot is:</p> <p><img src="https://i.stack.imgur.com/iQvKQ.png" alt="enter image description here"></p> <p>How do I tell ggplot to plot the c1 column in the given order rather than the natural sort order for the "character" type ?</p> <p>SessionInfo():</p> <pre><code>R version 2.14.1 (2011-12-22) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=fr_FR.UTF-8 LC_NUMERIC=C LC_TIME=fr_FR.UTF-8 LC_COLLATE=fr_FR.UTF-8 [5] LC_MONETARY=fr_FR.UTF-8 LC_MESSAGES=fr_FR.UTF-8 LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] plyr_1.7.1 ggplot2_0.9.2.1 loaded via a namespace (and not attached): [1] colorspace_1.2-0 dichromat_1.2-4 digest_0.5.2 grid_2.14.1 gtable_0.1.1 labeling_0.1 [7] MASS_7.3-16 memoise_0.1 munsell_0.4 proto_0.3-9.2 RColorBrewer_1.0-5 reshape2_1.2.1 [13] scales_0.2.2 stringr_0.6.1 tools_2.14.1 </code></pre> <p>dput(df):</p> <pre><code>structure(list(c1 = structure(c(8L, 1L, 9L, 2L, 4L, 5L, 3L, 7L, 10L, 6L), .Label = c("1", "10", "2", "3", "4", "5", "6", "7", "8", "9"), class = "factor"), c2 = structure(c(15343, 15378, 15416, 15508, 15543, 15547, 15548, 15551, 15558, 15625), class = "Date")), .Names = c("c1", "c2"), row.names = c(NA, -10L), class = "data.frame") </code></pre>
 

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