[R] ggplot - class "character" problem

David Menezes david.n.menezes at gmail.com
Tue Sep 13 12:00:46 CEST 2011


I'm trying to use ggplot2 to chart a dataset that I've drawn in from
excel.  When I run the qplot command, I get the following error

Error: ggplot2 doesn't know how to deal with data of class character

It feels like I need to coerce one of the fields in my data frame.
Here's the code, which is short:

#draw data in from network location
setwd("S:\\790\\Actuarial\\KFC\\609 Kernel\\Sensitivity
Tests\\Stressed ESG inputs")
input<-read.csv("yieldcurve plus 1pct abs.csv",header=FALSE)

#label columns

#create a data frame that i hope! will work with ggplot..

qplot(time,yield,data="flat_data",facets = yrs_ahead~.)

now the error.

In terms of the data format, head(flat data) returns the following:

> head(flat_data)
  scenID yrs_ahead      yield time
1      1         0 0.01637218  0.5
2      1         1 0.02446376  0.5
3      1         2 0.04501267  0.5
4      1         3 0.06947724  0.5
5      1         4 0.08262982  0.5
6      1         5 0.09761927  0.5

1) Am I right that it's about coercion of variable type?
2) Any ideas how to proceed?

Many thanks,

More information about the R-help mailing list