Pregunta

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.?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top