Dear all: I am trying to center labels on my plot with not much success. I have tried text(), mtext() but it's not working. I think I am using the wrong function for my task. Any help will be appreciated. My working codes. axis(1, at=c(1,2,3,4,5),font.lab=2,cex.axis=1.5,cex.lab=3,label=c("W0","CWH2","CWHmc","CH2","CHmc") ,text=c(1.5,2.5,3.5,4.5,5.5)) Many thanks in advance YA -- View this message in context: http://r.789695.n4.nabble.com/Centering-labels-on-X-axis-tp4646761.html Sent from the R help mailing list archive at Nabble.com.
Hello, Your working code needs a plot first: plot(1:5, xaxt = "n") And there's no 'text' argument to axis(). As for the centering of axis labels, they're centered on my graphics device. Exactly what is happening to yours? > sessionInfo() R version 2.15.1 (2012-06-22) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Portuguese_Portugal.1252 LC_CTYPE=Portuguese_Portugal.1252 [3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Portugal.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.2 igraph_0.6-2 loaded via a namespace (and not attached): [1] colorspace_1.1-1 dichromat_1.2-4 digest_0.5.2 fortunes_1.5-0 [5] grid_2.15.1 gtable_0.1.1 labeling_0.1 MASS_7.3-21 [9] memoise_0.1 munsell_0.3 plyr_1.7.1 proto_0.3-9.2 [13] RColorBrewer_1.0-5 reshape2_1.2.1 scales_0.2.2 stringr_0.6.1 [17] tools_2.15.1 Hope this helps, Rui Barradas Em 19-10-2012 15:39, YAddo escreveu:> Dear all: > I am trying to center labels on my plot with not much success. I have tried > text(), mtext() but it's not working. I think I am using the wrong function > for my task. > > Any help will be appreciated. > > My working codes. > axis(1, > at=c(1,2,3,4,5),font.lab=2,cex.axis=1.5,cex.lab=3,label=c("W0","CWH2","CWHmc","CH2","CHmc") > ,text=c(1.5,2.5,3.5,4.5,5.5)) > > Many thanks in advance > YA > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Centering-labels-on-X-axis-tp4646761.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
On 10/20/2012 01:39 AM, YAddo wrote:> Dear all: > I am trying to center labels on my plot with not much success. I have tried > text(), mtext() but it's not working. I think I am using the wrong function > for my task. > > Any help will be appreciated. > > My working codes. > axis(1, > at=c(1,2,3,4,5),font.lab=2,cex.axis=1.5,cex.lab=3,label=c("W0","CWH2","CWHmc","CH2","CHmc") > ,text=c(1.5,2.5,3.5,4.5,5.5)) >Hi YAddo, Perhaps the most common problem with getting the positions of axis labels right occurs with barplots. The bars in the standard "barplot" function are not centered on integer values, but the centers are returned from the function: barpos<-barplot(...) axis(1,at=barpos,...) Is this the problem you are having? Jim
Thanks Jim and Rui. My apologies, i did not give enough info on my plot. I am using : plot(x,y) for a line plot. I want to center the labels on the x-axis for each tick. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Centering-labels-on-X-axis-tp4646761p4646888.html Sent from the R help mailing list archive at Nabble.com.
On Oct 20, 2012, at 3:03 PM, YAddo wrote:> Thanks Jim and Rui. > > My apologies, i did not give enough info on my plot.Nor do you even now. Offer a data example.> > I am using : plot(x,y) for a line plot. I want to center the labels on the > x-axis for each tick.Code. We want code. -- David Winsemius, MD Alameda, CA, USA
On 10/21/2012 09:03 AM, YAddo wrote:> Thanks Jim and Rui. > > My apologies, i did not give enough info on my plot. > > I am using : plot(x,y) for a line plot. I want to center the labels on the > x-axis for each tick. >Hi YAddo, This is another guess, that you have more ticks than labels because they are closely spaced. Have a look at the staxlab function in the plotrix package. Jim