0

I have a plot where the y axis is transformed in percents; I would like to put limits on it to show only the high percents (from 50% to 100%) but it does not work :

  ggplot(myData,aes(x=A_factor, y=some_numeric_data, fill=factor(Another_factor))) + 
  geom_bar(position = position_fill(reverse = TRUE),stat = "identity", color="white") +
  scale_y_continuous(labels = scales::percent, limits=c(50,100))

I also tried with labels = percent_format.

Thanks.

Micawber
  • 707
  • 1
  • 5
  • 19
  • 1
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you – Axeman Aug 31 '17 at 12:09

1 Answers1

0

The values underlying the labels are decimal representations. Your limits should be set between 0 and 1. In your case:

limits = c(0.5, 1)
Jake Kaupp
  • 7,892
  • 2
  • 26
  • 36
  • I cant' believe I did not figured that out. I face another problem now : it gives me the limits I wanted, but now the plot is empty... – Micawber Aug 31 '17 at 12:13
  • Are your data in percents? Also, please consider accepting the answer (check mark to the left) if this answer helped you – CPak Aug 31 '17 at 12:29
  • No, the data are not in percent. – Micawber Aug 31 '17 at 12:44
  • Try `range(myData$some_number)` check to see if it's actually a percentage. Debugging your data and approach is something you should do when something "doesn't work" – Jake Kaupp Aug 31 '17 at 13:02
  • It's not, it goes from 0 to 2216. The labels = scales::percent automatically convert the data in percent (it works when I don't try to limit the y axis). – Micawber Aug 31 '17 at 13:10
  • You might want to check out `?scales::percent`. The way you are using it is just to construct a label. It does absolutely nothing to the underlying data. What you are plotting is the values of 0 to 2216, which is not a percentage representation of your data but it happens to have labels between "0%" and "221600%". – Jake Kaupp Aug 31 '17 at 14:12