Is there a way to be able to set both the axis range and the number of tick marks in the python implementation of ggplot for a scatterplot? For example, I want to set the y-axis to be from 0 to 100 with a tick at values 0, 10, 20, 30,...,100.
I've tried the following:
ggplot(aes(x=x, y=y), data=data) + geom_point() + scale_y_continuous(limits=(0,100), breaks=range(0,100,10))
ggplot(aes(x=x, y=y), data=data) + geom_point() + scale_y_continuous(breaks=range(0,100,10)) + ylim(0,100)
ggplot(aes(x=x, y=y), data=data) + geom_point() + scale_y_continuous(breaks=range(0,100,10))
In the first two lines, the limits override the breaks, so I get an axis from 0 to 100 but the tick marks do not appear. In the last line, the breaks do appear, but the range is only the automatic range that ggplot uses from the data, rather than the desired 0 to 100 range.
The default value of Y-axis tick marks using ggplot2 are taken by R using the provided data but we can set it by using scale_y_continuous function of ggplot2 package. For example, if we want to have values starting from 1 to 10 with a gap of 1 then we can use scale_y_continuous(breaks=seq(1,10,by=1)).
Use scale_xx() functions It is also possible to use the functions scale_x_continuous() and scale_y_continuous() to change x and y axis limits, respectively.
Option 1. Set xaxt = "n" and yaxt = "n" to remove the tick labels of the plot and add the new labels with the axis function. Note that the at argument sets where to show the tick marks.
The problem described here is currently not reproducible. Use ggplot 0.11.5 to remedy the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With