[R] ggplot2 will not draw a rectangle. Error: ggplot2 doesn't know how to deal with data of class XXX"
Sarah Goslee
sarah.goslee at gmail.com
Fri Mar 22 21:49:34 CET 2013
Hi John,
This bit of your code:
geom_rect(data=rect
Your reproducible example doesn't create rect, and rect() already
exists, so geom_rect() is trying to treat a function as data.
Sarah
On Fri, Mar 22, 2013 at 4:42 PM, John Kane <jrkrideau at inbox.com> wrote:
> What am I missing? When I run the code below I get the error message
> "Error: ggplot2 doesn't know how to deal with data of class function"
>
> Googling suggests a message of "Error: ggplot2 doesn't know how to deal with data of class XXX" is not uncommon but I don't see why I am getting a "function" error unless I am using some reserved word?
>
> ##=============Start Code=========================
> library(ggplot2)
>
> fcs <- structure(list(year = structure(c(954478800, 986014800, 1017550800,
> 1049086800, 1080709200, 1112245200, 1143781200, 1175313600, 1206936000,
> 1238472000, 1270008000, 1301544000, 1333166400), class = c("POSIXct",
> "POSIXt"), tzone = ""), federal.ps = c(211925L, 223933L, 237251L,
> 242737L, 244158L, 243971L, 249932L, 254622L, 263114L, 274370L,
> 282955L, 282352L, 278092L)), .Names = c("year", "federal.ps"),
> class = "data.frame", row.names = c(NA, -13L))
>
>
> p <- ggplot(fcs, aes(year, federal.ps )) + geom_line()
>
> p + geom_rect(data=rect, aes(xmin=xmin, xmax = xmax, ymin=-Inf, ymax = Inf),
> fill='red', alpha=0.2)
> ##=============End Code==========================
>
> sessionInfo()
> R version 2.15.3 (2013-03-01)
> Platform: i686-pc-linux-gnu (32-bit)
>
> locale:
> [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C
> [3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_CA.UTF-8
> [5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8
> [7] LC_PAPER=C LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> other attached packages:
> [1] ggplot2_0.9.3
>
> loaded via a namespace (and not attached):
> [1] colorspace_1.2-1 dichromat_2.0-0 digest_0.6.3 grid_2.15.3
> [5] gtable_0.1.2 labeling_0.1 MASS_7.3-23 munsell_0.4
> [9] plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2
> [13] scales_0.2.3 stringr_0.6.2
>
>
> John Kane
> Kingston ON Canada
>
>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list