[R] Converting plots to ggplot2

Domenico Vistocco vistocco at unicas.it
Thu Jan 17 17:12:48 CET 2008


Thompson, David (MNR) wrote:
> 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)
>   
You should add together the two lines:
p + geom_vline(intercept=45*pi/180) + geom_vline(intercept=225*pi/180)
> nor find a reference to manipulating the axes labels
> (still searching the news archives though).
>   
last_plot() + scale_x_continuous(name="x axis") + 
scale_y_continuous(name="y axis")

Ciao,
domenico
> 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) 
> i386-pc-mingw32 
>
> locale:
> LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;
> LC_MONETARY=English_Canada.1252;LC_NUMERIC=C;
> LC_TIME=English_Canada.1252
>
> attached base packages:
>  [1] datasets  tcltk     utils     stats     graphics  grDevices splines
> grid     
>  [9] methods   base     
>
> other attached packages:
>  [1] svGUI_0.9-5        svViews_0.9-5      svIO_0.9-5
> svMisc_0.9-5      
>  [5] R2HTML_1.58        ggplot2_0.5.2      RColorBrewer_0.2-3
> MASS_7.2-34       
>  [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
> http://ofri.mnr.gov.on.ca
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list