reverse log x-axis

761 views
Skip to first unread message

phi...@gmail.com

unread,
Aug 2, 2014, 5:48:47 PM8/2/14
to ggp...@googlegroups.com
Hi!

I have a problem with reversing a log x-axis in ggplot. Here is my code:

lambda <- c(0.5653575319,  0.5144245631,  0.4584984933,  0.4077608777,  0.3734203989  0.3390683833,  0.3144960567,
              0.2889876096,  0.2573098916,  0.2268758651,  0.1959987534,  0.1657206496  0.1390814475,  0.1126371312,
              0.0869576738,  0.0666142143,  0.0529221747,  0.0459094227,  0.0435728234  0.0421749374,  0.0386231044,
              0.0270527626,  0.0154564383,  0.0020047625, -0.0003503735, -0.0107725653 -0.0097896394, -0.0142337166,
             -0.0055407872, -0.0034185364, -0.0073841739, -0.0028702151,  0.0001600470, -0.0125737857)

xscale_limits <- seq(2.3,9.3,0.21)
xbreaks1 <- c(10,60,120,600,6000)

d<-data.frame(x=scales, y=lambda)

p =ggplot(d, aes(x)) + 
  geom_line(aes(y=y )) + 
  scale_x_log10(breaks=xbreaks1)

#So far, everything looks just fine.  Next, I transform the values on the x-axis according to:

trans_scales <- 1/scales *1000 

#and my new breaks should be: 

xbreaks2 <- c(100,10,2,1,0.17) #(according to xbreaks1)

Now, I want the values on the  x-axis to start at 100 and become smaller towards the right. The shape of the graph should not change. Unfortunately scale_x_reverse() changes only the values but not the log-scale itself. I will add a photoshoped picture to make clear how the graph should look like.
Thank for any help.



Screen Shot 2014-08-02 at 23.37.17.png

Brian Diggs

unread,
Aug 4, 2014, 12:07:44 PM8/4/14
to phi771-Re5JQEe...@public.gmane.org, ggplot2
Do the answers/code at either

http://stackoverflow.com/q/11053899/892313
http://blog.ggplot2.org/post/25938265813/defining-a-new-transformation-for-ggplot2-scales

help you?

--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

phi...@gmail.com

unread,
Aug 5, 2014, 10:36:05 AM8/5/14
to ggp...@googlegroups.com, phi771-Re5JQEe...@public.gmane.org
Hey Brian! Thanks a lot for the links. The first one I have found on my own. I tried to apply this for my case and failed miserably :( The second link looks very promising. However, in the meantime I have found another issue in my analysis process, that makes the graph unnecessary.
Anyways, Thanks a lot for your help!
Reply all
Reply to author
Forward
0 new messages