Problem with arrows in geom_segme​nt()

813 views
Skip to first unread message

Jonas Tundo

unread,
Mar 2, 2012, 5:04:46 AM3/2/12
to ggp...@googlegroups.com

Hi,

I get an error when using the arrow function in geom_segment(). I didn't find a solution in the "Changes and Additions to ggplot2-0.9.0" doc. Am I missing something or is it a bug?

See the example below (source http://stackoverflow.com/questions/7451116/arrows-label-direction-in-ggplot2):

 

set.seed(12345) 

AData <- data.frame(Glabel=LETTERS[1:7], A=rnorm(7, mean = 0, sd = 1), B=rnorm(7, mean = 0, sd = 1))

TData <- data.frame(Tlabel=LETTERS[11:20], A=rnorm(10, mean = 0, sd = 1), B=rnorm(10, mean = 0, sd = 1))

i <- 2

j <- 3

p <- ggplot(data=AData, aes(AData[, i], AData[, j])) + geom_point() + theme_bw()

p <- p + geom_text(aes(data=AData, label=Glabel), size=3, vjust=1.25, colour="black")

p <- p + geom_segment(data = TData, aes(xend = TData[ ,i], yend=TData[ ,j]),               x=0, y=0, colour="black",               arrow=arrow(angle=25, length=unit(0.25, "cm")))

p <- p + geom_text(data=TData, aes(x=TData[ ,i], y=TData[ ,j], label=Tlabel), size=3, vjust=1.35, colour="black")

 

 

When I run it:

> set.seed(12345) 

> AData <- data.frame(Glabel=LETTERS[1:7], A=rnorm(7, mean = 0, sd = 1), B=rnorm(7, mean = 0, sd = 1))

> TData <- data.frame(Tlabel=LETTERS[11:20], A=rnorm(10, mean = 0, sd = 1), B=rnorm(10, mean = 0, sd = 1))

> i <- 2

> j <- 3

> p <- ggplot(data=AData, aes(AData[, i], AData[, j])) + geom_point() + theme_bw()

> p <- p + geom_text(aes(data=AData, label=Glabel), size=3, vjust=1.25, colour="black")

> p <- p + geom_segment(data = TData, aes(xend = TData[ ,i], yend=TData[ ,j]),               x=0, y=0, colour="black",               arrow=arrow(angle=25, length=unit(0.25, "cm")))

Error in do.call("layer", list(mapping = mapping, data = data, stat = stat,  :

  could not find function "arrow"

> p <- p + geom_text(data=TData, aes(x=TData[ ,i], y=TData[ ,j], label=Tlabel), size=3, vjust=1.35, colour="black")

 

 

> sessionInfo()

R version 2.14.2 (2012-02-29)

Platform: i386-pc-mingw32/i386 (32-bit)

locale:

[1] LC_COLLATE=Dutch_Belgium.1252  LC_CTYPE=Dutch_Belgium.1252  

[3] LC_MONETARY=Dutch_Belgium.1252 LC_NUMERIC=C                 

[5] LC_TIME=Dutch_Belgium.1252   

attached base packages:

[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:

[1] ggplot2_0.9.0

loaded via a namespace (and not attached):

[1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.1       grid_2.14.2      

 [5] MASS_7.3-17        memoise_0.1        munsell_0.3        plyr_1.7.1       

 [9] proto_0.3-9.2      RColorBrewer_1.0-5 reshape2_1.2.1     scales_0.2.0     

[13] stringr_0.6

 

Best Regards,

Jonas

Jonas Tundo

unread,
Mar 2, 2012, 5:47:51 AM3/2/12
to ggplot2

Hadley Wickham

unread,
Mar 2, 2012, 12:59:20 PM3/2/12
to Jonas Tundo, ggp...@googlegroups.com
You now need to load grid:

library(grid)

Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages