log 10 scale, but tick labels in decimals

962 views
Skip to first unread message

JR Flanders

unread,
Feb 4, 2015, 6:02:30 PM2/4/15
to ggp...@googlegroups.com
I'm struggling with how to show tick labels as decimals (0.01, 0.1, 1...) rather than integers to the base 10 (-2, -1, 0...). Can any of the scales arguments handle this? 

Dennis Murphy

unread,
Feb 4, 2015, 9:26:15 PM2/4/15
to JR Flanders, ggplot2
Hi:

Is this what you had in mind?

set.seed(253089)
DF <- data.frame(x = 1:20, y = runif(20, 0.0001, 10))

library(ggplot2)
ggplot(DF, aes(x = x, y = y)) +
geom_point() +
scale_y_log10(limits = c(0.000, 10), breaks = c(0.01, 0.1, 0.5, 1, 5, 10))

Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Pablo marin-garcia

unread,
Feb 11, 2015, 9:20:59 PM2/11/15
to ggplot2


Hello Dennis,

I think that you have a typo in the Y lower limit  and it should have at least one 1 at the end: 0.001. Otherwise it fails.

scale_y_log10(limits = c(0.001, 10), breaks = c(0.01, 0.1, 0.5, 1, 5, 10))

You can see plots generated at http://rpubs.com/pamag/59196
I know you can not log-transform data with 0 but I was not expecting to have breaks and limits evaluating the values passed to them. If breaks or limits contain explicitly a 0 the plot fails.


I assume is better to transform the data beforehand and use a scale_y_continuos() for cases you want to plot 0 or negative Y values.

Pablo.

Dennis Murphy

unread,
Feb 11, 2015, 11:51:26 PM2/11/15
to Pablo marin-garcia, ggplot2
Hi:

Thanks for the catch. When I was testing, I used 0.0001 as the lower limit, not 0. I must have mis-typed somewhere when writing the reply. It isn't the first time...

Dennis

JR Flanders

unread,
Feb 12, 2015, 9:09:37 AM2/12/15
to Dennis Murphy, Pablo marin-garcia, ggplot2
Thank you for the replies. I am not sure what went wrong, but the behavior I desired is the the default for ggplot. The following scale argument worked just fine:

scale_x_log10(breaks=c(.01,.1,1,10))


You received this message because you are subscribed to a topic in the Google Groups "ggplot2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ggplot2/r5G4hD3-tDk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ggplot2+u...@googlegroups.com.

Alvaro Morales

unread,
May 20, 2020, 3:50:44 PM5/20/20
to ggplot2
Hi, how would you show the tick labels without decimal if it's above 1?. For example: 0.001, 0.01, 0.1, 1, 10 , 100  and not: 0.001, 0.010, 0.100, 1.000, 10.000, 100.000
> To unsubscribe: email ggp...@googlegroups.com

> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggp...@googlegroups.com

More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggp...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggp...@googlegroups.com

More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggp...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggp...@googlegroups.com

More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to a topic in the Google Groups "ggplot2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ggplot2/r5G4hD3-tDk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ggp...@googlegroups.com.

Ista Zahn

unread,
May 20, 2020, 7:00:34 PM5/20/20
to ggplot2
  scale_y_log10(breaks = c(0.001, 0.01, 0.1, 1, 10 , 100),
                labels
= c(0.001, 0.01, 0.1, 1, 10 , 100))
Reply all
Reply to author
Forward
0 new messages