-3

I have plotted ggplot bar plot in R. I would like to scale the Y axis according to the plot here....

I have values range 0-26000. I would like to plot bar plot with scale 0,30,26000. I have tried using breaks=c(0,30,2600) but it ticks the breaks.

Here is the plot with scaled axis.

http://wego.genomics.org.cn/cgi-bin/wego/index.pl

How to achieve this in R?

Any ideas.?

joran
  • 169,992
  • 32
  • 429
  • 468
user3573959
  • 385
  • 1
  • 3
  • 8
  • Please post a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that include sample data and what you've tried so far. – josliber May 05 '14 at 18:02

1 Answers1

0

Something like this?

library(ggplot2)
# generate sample data...
set.seed(1)
df <- data.frame(x=LETTERS[1:10],y=sample(1:10,10)^sample(1:5,10,replace=T))
# plot the data...
ggplot(df,aes(x,y))+
  geom_bar(stat="bin",fill="lightgreen",color="grey50")+
  scale_y_continuous(trans="log1p", breaks=c(0,30,2600))

The only way to do this is using some kind of mathematical transformation of the y-axis; otherwise, the graph is meaningless. Since your data covers > 4 orders of magnitude, a log transformation is a good candidate, except that you want 0 as the lower limit. So I used the "log1p" transformation which scales as log(y+1).

If you load the scales package (library(scales)) and type ?trans you'll see a very long list of available scale transformations. Oddly, to actually use these in ggplot as I did above, you do not have to load the scales package.

jlhoward
  • 58,004
  • 7
  • 97
  • 140
  • Many thanks for the code. Worked great. But I have 2 questions. I have plotted two series side by side with "dodge" option. When there is a 0 value for series 1 it place bar for series 2. Can i get empty space where no value for series? Another thing is is it possible to place a secondary y axis on the other side on facet plot? Thanks – user3573959 May 05 '14 at 18:31
  • You should post this as a new question, with examples of your data, your code, and your output. – jlhoward May 06 '14 at 04:59