[R] graphical output - customization of x axis

David Winsemius dwinsemius at comcast.net
Wed Jun 1 15:10:15 CEST 2011


Take out the pos=0 argument in your call to axis.

--  
David.
On Jun 1, 2011, at 8:56 AM, Christine SINOQUET wrote:

> Hello,
>
> I do not understand why the following source does not success in  
> customizing the x axis. The wished customization just consists in  
> labelling the x ticks with  
> "0kb","1kb","5kb","10kb","20kb","50kb","100kb","inf".
>
> pathFileName <- "test1.png"
>
>
> stats4H <- c(0.8623, 0.7142, 0.7211, 0.6753, 0.6290, 0.6157, 0.5919,  
> 0.5218)
> stats4W <- c(0.8724, 0.7889, 0.7253, 0.7235, 0.6860, 0.6630, 0.6424,  
> 0.5228)
>
> stats5H <- c(0.7610, 0.6832, 0.6310, 0.5527, 0.5231, 0.5600, 0.6147,  
> 0.5131)
>
> stats5W <- c(0.7740, 0.7641, 0.7099, 0.6918, 0.6483, 0.5769, 0.5539,  
> 0.4934)
>
>
> plotType <- "b"
>
>
> png(file=pathFileName, bg="transparent")
>
> xxf <- c("0kb","1kb","5kb","10kb","20kb","50kb","100kb","inf")
> xf  <- 1:8
>
> par(lab = c(length(xxf), 5, 7))
> #c(x, y, len)
> # ‘lab’ A numerical vector of the form ‘c(x, y, len)’ which modifies
> # the default way that axes are annotated. The values of ‘x’
> # and ‘y’ give the (approximate) number of tickmarks on the x
> # and y axes and ‘len’ specifies the label length.  The default
> # is ‘c(5, 5, 7)’.  Note that this only affects the way the
> # parameters ‘xaxp’ and ‘yaxp’ are set when the user coordinate
> # system is set up, and is not consulted when axes are drawn.
> # ‘len’ _is unimplemented_ in R.
>
>
> plot(stats4H, xlab = "half-width of window", ylab="AUC",  
> type=plotType, pch=7, col="blue", cex = 0.5,  
> ylim=c(0.4,1),xlim=c(1,8), xaxt = "n") # without x axis
>
> #If you are going to create a custom axis, you should suppress the  
> axis automatically generated by your high level plotting function.  
> The option axes=FALSE suppresses both x and y axes. xaxt="n" and  
> yaxt="n" suppress the x and y axis respectively.
>
> positions <- 1:8
> axis(side = 1, at=positions, labels=xxf , pos=0, lty=1,  
> col.axis="black", las=0)
>
> # side: bottom (1)
> # at: the points at which tick-marks are to be drawn
> # pos:coordinate of defined axis on the other axis
> # lty: linetype
> # col: line and tick marker color
> # las: labels are parallel (=0) or perpendicular(=2) to axis
> # tck: length of tick mark as fraction of plotting region (negative  
> number is outside graph,
> #      positive number is inside, 0 suppresses ticks, 1 creates  
> gridlines) default is -0.01
>
> lines(x = xf, y = stats4W, type=plotType, pch=15, col="green", cex =  
> 0.5)
> lines(x = xf, y = stats5H, type=plotType, pch=16, col="red", cex =  
> 0.5)
> lines(x = xf, y = stats5W, type=plotType, pch=17, col="magenta",cex  
> = 0.5)
>
>
> legend("bottomright",
>        legend = c("H, statistic S1", "W, statistic S1", "H,  
> statistic S2", "W, statistic S2"),
>        col = c("blue", "green", "red", "magenta"),
>        pch = c(7,15,16,17),
>        bty = "n",
>        cex = 0.8,
>        inset = c(0.1, 0.1))
>
> dev.off()
>
>
> I thank you in advance for any help.
>
> Best regards,
>
> Christine Sinoquet
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list