scale_y_continuous and limits not working
1
0
Entering edit mode
2.0 years ago

Hello, I don't know how to make a plot and indicate the limits for the y axis. I tried with:

ggplot() +
  geom_step(data = Pcal.msmc2, aes(x = time_scaled, y = Ne_scaled), color = "red") +
  ggtitle(my_title2, subtitle=my_subtitle2) +
  xlab("Years ago") +
  ylab("Number of individuals (Ne)") +
  annotation_logticks(sides = "bl") +
  scale_x_continuous(trans='log10', breaks=trans_breaks('log10', function(x) 10^x),
                     labels=trans_format('log10', math_format(10^.x))) +
  scale_y_continuous(trans='log10', breaks=trans_breaks('log10', function(x) 10^x),
                     labels=trans_format('log10', math_format(10^.x))) +
  expand_limits(x = c(100, 100000), y = c(0,1000))

But it didn't work, I got this image:

enter image description here

I want the plot only to show from 0 to 10000 on the y axis. How can I do that?

ggplot2 R • 1.5k views
ADD COMMENT
0
Entering edit mode

You can't include 0 on a log scale: log10(0) = -infinity (or rather, the limit as you approach 0 is -infinity... you get the idea).

Someone else will probably have a better answer about what you should do, though... use a broken y axis and special handling for zeros? use two panels? rethink using a log scale at all?

ADD REPLY
0
Entering edit mode
2.0 years ago
isd1989 • 0

You could try:

+ ylim(c(0, 10000))

However, this effectively truncates the plot, so it will not be representative of the trends in your data.

ADD COMMENT

Login before adding your answer.

Traffic: 1228 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6