title: plotting annual time series with pretty labels
body: <p>I have (macroeconomic) annual data from the "Penn World Tables". I'm having problems with the date labels. As you can see below, the dates are expressed as decimals. I've made several attempts to fix it, but failed repeatedly: I turn to you for help.</p>
  
  <p><img src="https://i.stack.imgur.com/6Ig4b.png" alt="enter image description here"></p>
  
  <p>This occurs, I think, because the "dates" (whole numbers like 2000, 2001, etc.) are treated as <code>numeric</code> rather than as <code>dates</code>. <strong>My main problem, therefore, is to fix the date format inside the dataframe for easy plotting.</strong></p>
  
  <p>If pwt indicates the name of my dataframe, and year indicates the column that stores the "dates", this is what I've tried, with no success:</p>
  
  <pre><code>pwt$year &lt;- strptime(pwt$year, format = "%Y")
  pwt$year &lt;- as.Date(as.character(pwt$year), format("%Y"), origin = "1970-01-01")
  pwt$year &lt;- as.Date(pwt$year, format='%Y-01-01', origin = "1970-01-01")
  pwt$year &lt;- as.yearmon(pwt$year) # requires zoo package
  </code></pre>
  
  <p><strong>Reproducible Code</strong></p>
  
  <p>Let me now present the data. I will show you steps that should recreate the data.</p>
  
  <pre><code>### Define directories
   if(.Platform$OS.type == "windows"){
     currentdir &lt;- "c:/R/pwt"
   } else {
   currentdir &lt;- "~/R/pwt"}
   setwd(currentdir)
  
  # download and save data in current directory
  download.file("http://www.rug.nl/research/GGDC/data/pwt/V80/pwt80.xlsx", "pwt80.xlsx", mode="wb")
  # **Edit** binary mode "wb" needed!
  
  # convert and save the data sheet in csv format
  library(gdata)
  installXLSXsupport() # support for xlsx format
  DataSheet &lt;- read.xls("pwt80.xlsx", sheet="Data") # load the Data sheet only
  write.csv(DataSheet, file=paste("pwt80", "csv", sep="."), row.names=FALSE)
  
  # read pwt80.csv data stored in current directory
  pwt80 &lt;- read.csv(paste(currentdir, "pwt80.csv", sep="/"))
  
  # use -subset- to get specifc countries and variables.
  countries &lt;- c("ESP", "ITA")
  variables &lt;- c("country", "countrycode", "year", "rgdpo", "pop")
  pwt &lt;- subset(#
    pwt80
    , countrycode %in% countries
    , select = variables
  )#
  </code></pre>
  
  <p>I am now interested in plotting the GDP per Capita for the above subsample of countries. So here is some code that intends to do that.</p>
  
  <pre><code># Plot data with qplot
  library(ggplot2)
  qp &lt;- qplot(#
    year
    , rgdpo/pop
    , data = subset(pwt80, countrycode %in% countries)
    , geom = "line"
    , group = countrycode
    , color = as.factor(countrycode)
  )#
  qp &lt;- qp + 
    xlab("") + 
    ylab("Real GDP Per Capita (international $, 2005 prices, chain)") + 
    theme(legend.title = element_blank()) + 
    coord_trans(y = "log10")
  </code></pre>
  
  <p>Dates look okay at this point, but things start to go wrong when I "zoom" with xlim and ylim:</p>
  
  <pre><code>qp &lt;- qp + xlim(2000,2010) + ylim(22000,35000)
  qp
  </code></pre>
  
  <p>The same problem exists if I use ggplot instead of qplot.</p>
  
  <pre><code># Plot data with ggplot
  ggp &lt;- ggplot(pwt,aes(x=year,y=rgdpo/pop,color=as.factor(countrycode),group=countrycode)) + 
    geom_line()  
  ggp &lt;- ggp + 
    xlab("") + 
    ylab("Real GDP Per Capita (international $, 2005 prices, chain)") + 
    theme(legend.title = element_blank()) + 
    coord_trans(y = "log10")
  ggp
  
  ggp &lt;- ggp + xlim(2000,2010) + ylim(22000,35000)
  ggp
  </code></pre>
  
  <p><strong>EDIT:</strong> Removed question related to <code>xts</code> objects. Removed the <code>dput()</code> to shorten question.</p>