Plot recipe for existing series type and own type

I am slightly confused how to properly add a plot recipe for a corrplot of an own-defined type.

Suppose that I have defined the following type

struct MyType
x::DataFrame
end

I would now like to have a corrplot for certain columns (and/or rows) similar to:

a = MyType(some_data)
corrplot(a, column_indices)

What kind of plot recipe do I have to use and how will it look like (I have tried several options, more or less successful)?

That’s because corrplot is a user recipe, so you can’t dispatch to it directly as a seriestype. Your solution should be something like

@recipe f(m::MyType, columns) = RecipesBase.recipetype(:corrplot, m.x[columns])
2 Likes

Thanks!

I have a very similar problem to this, except it is for graphplot instead.

When I try:

using RecipesBase, GraphRecipes

struct MyGraph end

@recipe function f(g::MyGraph)
    curves := false
    RecipesBase.recipetype(:graphplot, g)
end

I get:

ERROR: LoadError: No type recipe defined for type graphplot. You may need to load StatsPlots

graphplot comes from the GraphRecipes package, not StatsPlots, so I’m not sure how to respond to this error message.

What do I need to include or change so that I can do something like graphplot(mygraph)?

The recipetype function for graphplot is not defined. Either you add it yourself using RecipesBase.recipetype(::Val{:graphplot}, args...) = GraphRecipes.GraphPlot(args)
or you directly call the graphplot object in your recipe:

using RecipesBase,GraphRecipes
struct MyGraph end
@recipe function f(g::MyGraph)
   GraphRecipes.GraphPlot([rand(5,5)])
end
using Plots
g = MyGraph()
plot(g)
1 Like