I want to remove axis ticks from the x-axis without removing them from the y-axis.
Right now, I can get both to be removed using:
axis.ticks=theme_blank()
For instance:
# Generate data
c <- ggplot(mtcars, aes(factor(cyl)))
c + geom_bar()+opts(axis.ticks=theme_blank())
#c + geom_bar(width=.5)
#c + geom_bar() + coord_flip()
#c + geom_bar(fill="white", colour="darkgreen")
But I don't know how to control them independently.
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.
Specify y-Axis Tick Values for Specific Axes Call the nexttile function to create the axes objects ax1 and ax2 . Plot data into each axes. Set the y-axis ticks for the lower plot by passing ax2 as the first input argument to the yticks function.
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.
To remove just x axis ticks use axis.ticks.x=
c <- ggplot(mtcars, aes(factor(cyl)))
c + geom_bar()+opts(axis.ticks.x=theme_blank())
For the latest ggplot2 version (0.9.3) instead of opts()
use theme()
and element_blank()
.
c <- ggplot(mtcars, aes(factor(cyl)))
c + geom_bar()+theme(axis.ticks.x=element_blank())
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