caijun / ggcorrplot2

Implementation of corrplot using ggplot2
MIT License
38 stars 11 forks source link

Reimplement the various visualizing methods by creating geom layers #2

Open caijun opened 4 years ago

caijun commented 4 years ago

For example, geom_eclipse(), geom_circle(), geom_square() etc. for upper triangle matrix. The full type can be generated by overlaying a upper type on a lower type.

LDSamson commented 2 years ago

The idea is good. I would love to help with this if possible. Some thoughts below.

One way to implement this change is: leave the original ggcorrplot function largely similar, but when you define type = NULL, then only the base plot layer will be drawn, and you can do something like this:

geom_corrplot(corr, type = NULL) + 
geom_corrplot_ellipses(plot.type = "upper") + 
geom_corrplot_numbers(plot.type = "lower")

Is that what you had in mind?

The complexity of course is that there are many steps and layers, with some of them being conditional:

I think that, for this idea to work, we need to split up the ggcorrplot function in some smaller functions for the different steps performed, so that you can reuse the elements if needed: one for creating data, one for adding labels, one for customizing the legend, etcetera. Advantage is that you can also easier add unit testing for them that way.

Furthermore, to create the different geom functions, the ellipse visualization would be the hardest to implement since you calculate the ellipses manually. It would help if we don't calculate the ellipses ourselves, but instead use the function ggforce::geom_ellipse while setting the ellipse parameters a and b. That way you don't have to calculate the ellipses and none of the corrplot geoms require a new stat, which makes the separate geom_corrplot parts easier to handle.

LDSamson commented 2 years ago

See here; this version has quite some changes since I split up the main functions in several smaller ones. Some of the changes (I can make a more detailed log later if you want):

Let me know what you think. It can definitely still be improved but I think it is a good start in making the package more flexible. I can either create a pull request or I can make some changes first to tweak it further. EDIT: I see now that this version has still the legend.position option that was mentioned in ; we can remove that if you don't like it.

caijun commented 2 years ago

@LDSamson Thanks very much for your efforts in improving ggcorrplot2 package. I would like to re-desigin this package so that it can behave more like the grammar of ggplot2 package. I would expect the following syntax,

ggplot(corr) + 
geom_circle(type = "upper") + 
geom_number(type = "lower")

We can also add layers such as geom_circle(), geom_square(), geom_ellipse(),and geom_number() etc. And these layers can be plotted in types of upper, lower and full.