Extending ggplot2 properly?

后端 未结 3 840
闹比i
闹比i 2021-01-30 09:01

Recently a few neat uses of ggplot2 have come up, and either partial or full solutions have been posted:

  • ggheat
  • Curly braces
  • position_dynamic
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 09:23

    I am not certain that I agree with your analysis. I'll explain why, and will then point you to some resources for writing your own geoms.

    ggheat

    As far as I can tell, ggheat returns an object of class ggplot. Thus it is a convenient wrapper around ggplot, customised for a specific use case. Although qplot is far more generic, it does in principle the same thing: It is a wrapper around ggplot that makes some informed guesses about the data and chooses sensible defaults. Hadley calls this plot functions and it is described briefly on page 181 of the ggplot2 book.

    curly braces

    The curly brace solution does exactly what the ggplot philosophy says, i.e. separate data from presentation. In this case, the data is generated by a little custom function and is stored in a data.frame. It is then displayed using a geom that makes sense, i.e. geom_line.

    quo vadis?

    You have noted (in the r chat room) that you would prefer to have a more generic approach to plotting the curly braces. Something along the following lines (and I paraphrase and extend at the same time):

    • Supply data in the form of a bounding box coordinates (i.e. x0, x1, y0 and y1)
    • Specify a "statistic", such as brace, box or whatever
    • Specify a geom, such as geom_custom_shape

    This sounds like a nice generalisation and extension of the ideas behind the curly brace solution, and would clearly require writing a new geom. There is an official ggplot wiki, where you can find instructions for creating a new geom.

提交回复
热议问题