Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjusting axis range and tick marks in python ggplot

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.

like image 781
plam Avatar asked May 08 '14 18:05

plam


People also ask

How do I add a tick in ggplot2?

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)).

How do I change the y axis values in ggplot2?

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.

How do I change tick marks in R?

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.


1 Answers

The problem described here is currently not reproducible. Use ggplot 0.11.5 to remedy the problem.

like image 153
J_H Avatar answered Nov 08 '22 18:11

J_H