Add dollar sign to x-axis on plot

Viewed 146

I made this plot

data(iris)
plot(density(iris$Sepal.Length), xlab = "xlab")

enter image description here

I know this is non-sensical, but would there have been a way to add a "dollar sign" to each unit on the x-axis? For example:

enter image description here

I tried to this the following way:

library(priceR)
iris$Sepal.Length = format_dollars(iris$Sepal.Length)
plot(density(iris$Sepal.Length), xlab = "xlab")

But I don't think this is the right way to do this. Is there a more general way to simply add dollar signs ($) to each unit on the x-axis?

Thanks

1 Answers

Just redraw x-axis by pasteing axTicks(1) and $ together.

plot(density(iris$Sepal.Length), xlab="xlab", xaxt='n')
axis(1, axTicks(1), labels=paste0(axTicks(1), '$'))

enter image description here

Related