[R] Currency symbols in Xtick or Ytick labels

David Winsemius dwinsemius at comcast.net
Tue Jan 31 14:48:18 CET 2012


On Jan 30, 2012, at 8:07 PM, Eugene Gallagher wrote:

> How do you label Xtick and Ytick marks with Currency symbols: $2000
> instead of 2000? I would like to add dollar symbols to tickmarks on
> boxplots, histograms and back-to-back histograms.
>
>
>
> My Examples (requiring the lattice and Hmisc packages):
>
>
>
> data(case0102, package="Sleuth2")
>
> str(case0102)
>
> boxplot(Salary~Sex, case0102)
>
> histogram(~ Salary | Sex, data=case0102)

I didn't see the value in installing and loading a new package for  
illustrating this task. Using the example in ?histogram should be  
sufficient to demonstrate how to format axis labels for lattice plots:

  histogram( ~ height | voice.part, data = singer, nint = 17,
                 scales=list(x=list(at=seq(60,75,by=5),
                            labels=sprintf("$%2.0f", seq(60,75,by=5)))),
                 endpoints = c(59.5, 76.5), layout = c(2,4), aspect = 1,
                 xlab = "Height (inches)")

>
> require(Hmisc)
>
> # out <- histbackback(split(case0102$Salary, case0102$Sex),
> probability=TRUE, xlim=c(-.001,.001),
>
> out <- histbackback(split(case0102$Salary, case0102$Sex),
> probability=FALSE, xlim=c(-30,30),
>
>                    main = 'Sleuth Case 1.2')

'histbackback' does not use lattice graphics, so refer to the code and  
to ?axis

>
> #! just adding color
>
> barplot(-out$left, col="red" , horiz=TRUE, space=0, add=TRUE,
> axes=FALSE)

'barplot' is not a lattice function, either. You should look at ?axis.


-- 
David.
>
> barplot(out$right, col="blue", horiz=TRUE, space=0, add=TRUE,
> axes=FALSE)
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list