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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:11:14+00:00 2026-06-15T15:11:14+00:00

I’m trying to plot some date points: library(ggplot2) library(plyr) set.seed(1234) df <- data.frame( c1

  • 0

I’m trying to plot some date points:

library(ggplot2)
library(plyr)
set.seed(1234)

df <- 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 <- arrange(df,c2)
qplot(c2,c1,data=df) + scale_x_date(breaks="1 month")

Although I used arrange to sort the data, ggplot does not plot the data in order:
enter image description here

The expected plot is:

enter image description here

How do I tell ggplot to plot the c1 column in the given order rather than the natural sort order for the “character” type ?

SessionInfo():

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      

dput(df):

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")
  • 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-15T15:11:15+00:00Added an answer on June 15, 2026 at 3:11 pm

    There is no problem (with R).

    You have been plotting a random permutation of dates against a character vector of digits that were coerced from integer. You are getting exactly what you asked for. No need to reinstall R or any packages. The dates in the ‘c2’ column will get sorted in the process of constructing the plot, so there is no need to pre-sort them and doings so will have no effect.

    If on the the hand you want the the labels on the y axis to be the c1-values but the y-values to be the order-statistic (the integer order), then you need to plot 1:length(c1) against the date and change the default labels. (This remains a difficulty in your understanding of the expected behavior of a plotting process. There was no need to reinstall R.) This is the base graphics solution:

    > with(df, plot(c2,1:10, yaxt="n"))
    > axis(2, at=1:10, labels=df$c1)
    

    I find the ggplot documentation rather frustrating. Try to find how to substitute axis labels is something that is just not apparent. I tried update_labels without success. The use of a different language for plotting entities in that system remains an ongoing barrier for me. I know that many people have the opposite reaction and that ggplot2 is a favorite package for many. (Edit: this appears to create the desired plot in the ggplot world:)

    > p <- qplot(c2, 1:nrow(df),data=df) + scale_x_date(breaks="1 month")
    > p
    > p + scale_y_discrete( labels=df$c1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:

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.