Scale.y_continuous percentage format

Is there way to format the y axis as percentages in Gadfly?

Something like
Scale.y_continuous(format=:percent)

How about this?

image

using Gadfly

x = collect(1:100)
y = collect(0.01:.01:1.0)

plot(
    x = x,
    y = y,
    Geom.line,
    Scale.y_continuous(labels = n -> "$(n*100)%"),
    Guide.yticks(ticks = collect(0.0:0.1:1.0))
)

Ah!

Yes, that worked. I initally didnt add the Guide.yticks param, and ran into a fun old rounding error (30.0% was 30.000000000004%. But with ticks, worked perfectly.

Thank you!

1 Like

You can also round in the labels function if need be:

plot(
    x = x,
    y = y,
    Geom.line,
    Scale.y_continuous(labels = n -> "$(round(Int, 100n))%"),
    Guide.yticks(ticks = collect(0.0:0.1:1.0))
)

image

Gadfly is also compatible with Uniful.jl. Example:

using Gadfly, Unitful

y = 10*rand(10)*1u"percent"
p = plot(x=1:10, y=y, Geom.point)