R {ggplot2} Can I ask what are the mark marks for the plot?

Using an example from the Hadley website :

> (m <- qplot(rating, votes, data=subset(movies, votes > 1000), na.rm = T))

What creates:

example figure

My question is: Is it possible to determine which labels are marked after creating the plot object? (I want to remove the first automatically generated breakpoint)

Background:. The graph above shows that the gaps along the x axis are from 2 to 9. To get this manually, use:

m + scale_x_continuous( breaks = c(2:9) )

But I would like to determine from the figure what these labels are, so that I can delete some of them. In other words, there is a function that will return labels:

myBreaks <- tickMarks(m)

So that I can subsequently call:

m + scale_x_continuous( breaks = myBreaks[-1] )

where I removed the first gap from the array.

+4
source share
1 answer

I'm not sure if this is what you want, but you can do a hack:

 # drop first break sx <- scale_x_continuous() sx$.tr$input_breaks <- function(., range) grid.pretty(range)[-1] m <- qplot(rating, votes, data=subset(movies, votes > 1000), na.rm = T) m + sx # reduce the breaks into half sx$.tr$input_breaks <- function(., range) { r <- grid.pretty(range); r[seq_len(length(r)/2)*2] } m + sx # set the (rough) number of breaks sx$.tr$input_breaks <- function(., range) pretty(range, 3) m + sx 

but note that this also affects the y axis ...

And probably this is an easy way to make your own conversion object.

 TransIdentity2 <- Trans$new("identity2", "force", "force", "force") TransIdentity2$input_breaks <- function(., range) pretty(range, 3) m + scale_x_continuous(trans="identity2") 

in this case, it does not affect the y axis.

+3
source

All Articles