scale_y_continuous and limits not working
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:
I want the plot only to show from 0 to 10000 on the y axis. How can I do that?
• 2,420 views
•
link
1 answer
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.
• 0 views
•
link
Log in to answer this question.
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?