[R] Converting plots to ggplot2

Thompson, David (MNR) David.John.Thompson at ontario.ca
Thu Jan 17 15:53:59 CET 2008

Hello Hadley,

I am trying to reproduce the following with ggplot:
    a <- seq(0, 360, 5)*pi/180 ; a
    ac <- sin(a + (45*pi/180)) + 1 ; ac
    plot(a, ac, type='b', xaxt = "n")
    axis(1, at=seq(0,6,1), labels=round(seq(0,6,1)*180/pi),1)
    abline(v=c(45*pi/180, 225*pi/180))

I can get the basic plot:
    p <- qplot(a, ac, geom=c('point', 'line')) ; p

but cannot seem to add the vertical reference lines:
    # representing NE and SW compass points
    p + geom_vline(intercept=45*pi/180)
    p + geom_vline(intercept=225*pi/180)

nor find a reference to manipulating the axes labels
(still searching the news archives though).

Also, I would like to add additional curves to the same
plot with the sequence 'asc' generated by:
   s <- seq(5, 45, 10)*pi/180 ; s
   asc <- lapply(s, function(x) x*cos(ac) + x*sin(ac)) ; asc

Suggestions? Thanx, DaveT.

> sessionInfo()
R version 2.6.1 (2007-11-26) 


attached base packages:
 [1] datasets  tcltk     utils     stats     graphics  grDevices splines
 [9] methods   base     

other attached packages:
 [1] svGUI_0.9-5        svViews_0.9-5      svIO_0.9-5
 [5] R2HTML_1.58        ggplot2_0.5.2      RColorBrewer_0.2-3
 [9] proto_0.3-7        reshape_0.7.4     

loaded via a namespace (and not attached):
[1] lattice_0.14-17

> Sys.info()[c(1:3,5)]
                      sysname                       release 
                    "Windows"                      "NT 5.1" 
                      version                       machine 
"(build 2600) Service Pack 2"                         "x86" 
Silviculture Data Analyst
Ontario Forest Research Institute
Ontario Ministry of Natural Resources
david.john.thompson at ontario.ca

More information about the R-help mailing list