Hi,
I’m wondering what would be the approach to manipulate the theme inside my Geom
extension. I mainly would like to adjust the x_scale
and y_scale
at the moment. Also, I would like to edit the ticks
for instance.
Cheers,
Amir
Hi,
I’m wondering what would be the approach to manipulate the theme inside my Geom
extension. I mainly would like to adjust the x_scale
and y_scale
at the moment. Also, I would like to edit the ticks
for instance.
Cheers,
Amir
You should probably take a look at the scales package, which underlies ggplot2.
The scales packages provides the internal scaling infrastructure to ggplot2 and its functions allow users to customize the transformations, breaks, guides and palettes used in visualizations.
The section on Creating your own scales and mutable ranges is likely to be particularly relevant.
Scales got a lot of work, and had a major release this summer, so the post that accompanied that release may also be informative:
Thanks! This looks useful indeed, but I'm afraid that's not what I want, or I cannot see how.
I'm mainly wondering how should I incorporate different scaling into a ggproto
and ggplot2::Geom
object. I can plot the data in the draw_group
or draw_frame
for instance, but I am not sure where should I implement the theme-related options.
Hey @mrmsdbdl! AFAIK, plot theme options (eg. how axis ticks and labels are rendered) are generally distinct from scale options (which determine how data values are mapped to the axis) and distinct again from a geom's aesthetics. We might be able to help you more if you can be more specific about what you're trying to build
Thanks for your reply @rensa. So, I put an example that sort of demonstrate what I'd like to achieve. Please check my implementation of geom_sand
and stat_sand
in this GitHub Gist. As you can see, I'm following the standard procedure, and I'd like to write a ggextension
where I can draw some custom GeomSegment alongside the points that I'm drawing. So, the following code will produce the shown plot.
df <- data.frame(x = runif(10, 0, 10), y = runif(10, 0, 10))
ggplot(df, aes(x = x, y = y)) +
geom_sand(hl = 5, vl = 5)
I have a few questions regarding my implementation.
stat_sand
x
and y
ranges and limits?axis.ticks
or panel.grid.major.x
and panel.grid.minor.x
? _These are theme()
parameters that I can change easily on ggplot()
but I'm not sure how to properly change then in the ggextension
.compute_panel
— as I realized sometimes I have more control when using compute_panel
— will ggplot
be able to apply my geom_*
and stat_*
on groups or facets?I've tried to summarize everything, I hope I'm being clear here, if not, please let me know. In the meanwhile, I'm trying to google things but unfortunately, there is not a lot on the internet on developing ggextension
s. I read some codes too but I see that everyone has implemented their own hack for each of these problems, and I cannot find examples where people adjust the range
and axis.ticks
.
Thanks in advance for your help,
Amir.