math17
math17

Reputation: 17

How to force y axis to return values in scientific notation in R boxplot

How can I force the y axis to display the numbers in scientific notation with 'e'. For example, instead of 0.01, it should show "e-02". Here is my code below.

boxplot(large1k$Damping_error,small1k$Damping_error,large4k$Damping_error,small4k$Damping_error,large8k$Damping_error,small8k$Damping_error,large16k$Damping_error,small16k$Damping_error,large32k$Damping_error,small32k$Damping_error,col=c("blue","red","blue","red","blue","red","blue","red","blue","red"),names=c("1k","1k","4k","4k","8k","8k","16k","16k","32k","32k"),las.y=1,xlab="Sample  size",ylab="Damping error",log="y",cex.axis=1.2,cex.lab=1.3)

enter image description here

Upvotes: 0

Views: 778

Answers (1)

Kota Mori
Kota Mori

Reputation: 6740

Your probably need to do something like this.

labels_at <- seq(0, 25, 5)
labels <- scales::label_scientific(digits=2)(labels_at)
boxplot(count ~ spray, data = InsectSprays, col = "lightgray", yaxt="n")
axis(side=2, at=labels_at, labels=labels)

enter image description here

Upvotes: 1

Related Questions