[R] Problems to show X-labels when plotting small values

Jim Lemon jim at bitwrit.com.au
Wed Sep 11 03:49:14 CEST 2013


On 09/11/2013 09:06 AM, Charles Novaes de Santana wrote:
> Dear all,
>
> I am following instructions of FAQ 7.2 (
> http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f)
> to create rotated labels in my plots, but I am facing some problems when
> plotting variables with small values (in my case, values between 0.001 and
> 0.007).
>
> When I try to plot these small values, the X-label of my plot doesn't
> appear. Please find below the example I am trying to run:
>
> #Definition of my variable and of the labels
> a<-c(0.007,0.0004,0.0001)
> laba<-c("number1","number2","number3")
>
> #This plot doesn't work fine (label doesn't appear)
> par(mar = c(7, 4, 4, 2) + 0.1)
> plot(a,xaxt="n",xlab="",ylab="Y-Label")
> axis(1,labels=FALSE,tick=FALSE)
> mtext(1,text="X-Label",line=6)
> text(1:length(a), par("usr")[3] - 0.25, srt = 45, adj = 1,labels = a, xpd =
> TRUE,cex=0.75)
>
> #If I just multiply my variable, the plot works fine (label appears)
> par(mar = c(7, 4, 4, 2) + 0.1)
> plot(1000*a,xaxt="n",xlab="",ylab="Y-Label")
> axis(1,labels=FALSE,tick=FALSE)
> mtext(1,text="X-Label",line=6)
> text(1:length(a), par("usr")[3] - 0.25, srt = 45, adj = 1,labels = laba,
> xpd = TRUE,cex=0.75)
>
> Do you have any idea about why is it happening? I much appreciate any help!
>
Hi Charles,
The problem lies in your specification of the y values for the labels in 
the "text" call. Because you are subtracting a large value relative to 
the range of y values, the labels are displayed way off the bottom of 
the plot. Try this instead:

text(1:length(a),par("usr")[3]-0.0002,srt=45,adj=1,
  labels=a,xpd=TRUE,cex=0.75)

If you want to pass explicit values for the positions on the plot, check 
them against the x and y ranges.

Jim



More information about the R-help mailing list