K3rn3l5
K3rn3l5

Reputation: 361

ggplot with extreme values

ggplot bar graph

Have two questions -

1.What could be the best way to show / compare extreme values. The T group in the graph has value but no where close to the other groups, M & F

  1. Is the way I can show proper number on the Y axis without having to divide them by 1000s?

Upvotes: 2

Views: 1405

Answers (1)

LyzandeR
LyzandeR

Reputation: 37879

Assume a data.frame like the following:

#big values ranging from 10 to 100000 which would normally
#result to 10 not being shown
df <- data.frame(names=letters[1:3], values=c(100000,1000,10))

You can specify a log scale axis so that you can see both big and small values (uses log distance on the y axis) and also specify labels = comma from the scales library inside the scale_y_log10 function to print 'nice' numbers instead of scientific:

See the following:

library(ggplot2)
library(scales) #you need this for labels = comma
ggplot(aes(x=names, y=values), data=df) + geom_bar(stat='identity') + 
  #scale_y_log10 will log scale the y axis
  #labels = comma will create nice numbers
  scale_y_log10(labels = comma)

enter image description here

Upvotes: 3

Related Questions