Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature wishlist #50

Open
matthijscox opened this issue Aug 9, 2017 · 21 comments
Open

Feature wishlist #50

matthijscox opened this issue Aug 9, 2017 · 21 comments

Comments

@matthijscox
Copy link
Contributor

matthijscox commented Aug 9, 2017

Hi Pier,

Personally, I had the wish for some extra features (do you have a general wish/todo list somewhere?):

  • Facet axes spacing/margin options (I wanted tighter custom spacing, per direction customizable).
  • Vector/quiver plots (these I use a lot, and I have custom patch function for this now).
  • Continuous size scale (also nice together with the vector headsize for example)

The axes spacing and margins seemed to be hardcoded right now, so that one looks quite hard to change.

The vector plots would require an additional input interface, like 'xend' and 'yend' indicating the end of the vectors. Or alternatively you could use a length input 'dx', 'dy'.

@piermorel
Copy link
Owner

piermorel commented Aug 9, 2017

Hi,

There is no general wishlist/todo... opened issues and pull requests kind of act as one :) But it could be a good idea to have something somewhere (wiki for example... I still have an open pull request for more documentation!).

Current or short-term todo for me:
✅ I'm preparing an overhaul of the legend and color stuff. A lot of it is internal but this will bring the possibility to use custom colormaps that integrate lightness such as brewer paired and D3.JS colormaps (and not only LCH). There will be the possibility to have a combined color/lightness legend. Ultimately I also want to have matrix-like legend for color-lighness.
• Foreground/background choice for geom_polygon() and geom_Xline() should be not too hard to implement.

A bit more long term:
✅ I want to see if I can find a better way to handle legend sizes when multiple gramm plots are made with a matrix of gramm objects. This will touch axes spacing, which is pretty tricky/hackish in gramm (code both in draw() and especially in redraw()).
• One thing that I might try to add are image/surf plots because it's the kind of stuff we might use in the lab, but I'm still not sure this would fit well within gramm
• Marginal histograms (also a major hassle with redraw())

As for your suggestions:
✅ Do you know that it's already possible to change spacing by calling g.redraw(spacing) ? It's only uniform though... but by being thorough it's possibly a change you can make yourself by looking in draw() and redraw().
• If I were you I would also hold off the continuous size scale until the legend overhaul is done... but judging how annoying continuous colors were to implement, continuous size scale would be quite some work, especially if you want it to work together with continuous color in a variety of geoms. You are welcome to try but this is the kind of stuff that will require changes in a lot of places. It might be easier to "fake it" (i.e. discretize sizes internally to minimize changes and just change how size legends are presented).
• I have no use for quivers, so didn't plan anything there, but if you have some working code it would be a great add. Internally, I guess that it would use 'x' and 'y' and that we would need new 'u' and 'v' inputs for gramm (that would be treated the same way as facultative ones like 'ymin','ymax','z').

@matthijscox
Copy link
Contributor Author

It's indeed good to know your plans before trying more myself.

If we're talking documentation, I also love the ggplot style cheatsheet. But I haven't investigated yet how they made it, so I don't know if it's a lot of work.

I was unaware of g.redraw(spacing), good that you mention it.
I'll look into the quivers, but I will also have to investigate if I am allowed to make it public.

@matthijscox
Copy link
Contributor Author

Is datetime support already a feature. Because it fails for me.
If it's not a feature, you can add it to the wishlist :)

t1 = datetime(2017,8,1,8,0,0);
t2 = datetime(2017,8,5,8,0,0);
t = t1:t2;
y = 1:numel(t);

g=gramm('x',t,'y',y);
g.geom_point();
figure;
g.draw;

Error using datetime/max (line 107)
Comparison is not defined between datetime and double arrays.

Error in gramm/draw (line 318)
obj.plot_lim.maxx(obj.current_row,obj.current_column)=max(allmax(temp_aes.x(sel_column)),...

@piermorel
Copy link
Owner

No, but datenum() works... saves me the hassle of needing to check Matlab versions for yet another thing!

t1 = datenum(2017,8,1,8,0,0);
t2 = datenum(2017,8,5,8,0,0);
t = t1:t2;
y = 1:numel(t);

g=gramm('x',t,'y',y);
g.geom_point();
g.set_datetick('x')
figure;
g.draw;

@Leberer
Copy link

Leberer commented Aug 13, 2017

Is it possible to display a legend when no grouping variable is used? Maybe I'm too stupid but I can't seem to get the legend displayed in this case.
It would be great to have, for example I'm plotting the geom_point() and stat_smooth() in one plot and it would make sense to me to have a legend entry for these two.

@piermorel
Copy link
Owner

@Leberer It's not possible currently as legends display grouping variables and not geom/stats. If there is only a single group the legend is not displayed. I'm not sure about what you want to achieve in your case though: a point with the legend "data points" and a line with the legend "smoothed line"?

This seems like a lot of work for an edge case: what is plotted is typically in the Y axis label or title, and details like that in the figure text legend. An optional additional line of text in the legend (a kind of "side title") could be doable though, would that be useful?

@matthijscox
Copy link
Contributor Author

Hi Pier,

A question that is perhaps related to custom axes margins. Is it already possible to make custom axes widths/heights? For example in a facet_grid or in multiple calls to gramm. I couldn't find it in the documentation (only space=free, but then the space depends on the data, not on my own choice).

With subplot it's possible to make for example the left axes 2x wider than the right axes. This is sometimes nice with a trend plot and a histogram next to each other, where you want to put the emphasis on the trend plot.

@piermorel
Copy link
Owner

Hi Matthijs,

It is already possible to do that in the "multiple gramm call" case as gramm figures can be created in UIpanels. It's a bit hackish but works: see issue #40 . When I change things on axes spacing I will see if I can make that less hackish.

Apart from that, it's currently not possible to have custom facet width/heights beyond the data driven 'space','free'. However I think that for facets it makes little sense to have anything else (not to mention that since they are data driven, custom sizes might break if the number of facets changes).

@piermorel
Copy link
Owner

For those who get notifications from this thread... recent commits added a lot of requested customization features (see my edited "wishlist" above). The latest one allows to fully customize sizes @matthijscox ! Let me know how that works for you.

@matthijscox
Copy link
Contributor Author

That looks great! I see you also updated the cheatsheet, so we'll have a go with it.

@matiasandina
Copy link

matiasandina commented Mar 8, 2018

Thanks for such a beautiful package! Not sure if this fits here but I wonder if there's a way to plot all columns of a table as Y vectors using the length (or a defined column vector). I was thinking about doing something like:

function g = multiplot(inputTable)


x = 1:size(inputTable,1);

vars_to_plot = inputTable.Properties.VariableNames;

     for my_vars = 1:length(vars_to_plot)
           
     g(my_vars, 1) = gramm('x', x, 'y', eval(strcat('inputTable.', vars_to_plot{my_vars})));
     g(my_vars,1).geom_point();
     
   
     end
     
g.draw()
    
end

The whole eval is dirty. I also wonder how to include other aesthetics, should I go with switch/case?

@matthijscox
Copy link
Contributor Author

Hi Matia,

I'll try to answer for Pier. I think what you want is to use the facet_wrap or facet_grid functionality, together with converting your data to single columns for gramm.

Here is an example:

% create some fake input table
inputTable = array2table(rand(50,8));

% get the input size
sz = size(inputTable);
n_row = sz(1);
n_var = sz(2);

% convert inputTable into a column array
inputData = table2array(inputTable);
inputColumn = inputData(:)';

% convert variable names to a column array (do you have a Matlab version with repelem? it's great!)
variableNames = inputTable.Properties.VariableNames;
variableColumn = repelem(variableNames,n_row)';

% create x data column array
xColumn = repmat(1:n_row,1,n_var)';

% create a gramm object that is facet wrapped on the variable
f = figure('Position',[100 100 800 400]);
g = gramm('x',xColumn,'y',inputColumn,'color',variableColumn); % add the color aesthetic
g.facet_wrap(variableColumn);
g.geom_point();
g.geom_line(); % and another geometry
g.draw();

image

@piermorel
Copy link
Owner

Thanks for the help in answering @matthijscox ! Your answer is indeed spot on... to be even faster with the conversion from "wide" table to "long" table, this can be done in a single line using stack(). There is actually an example related to this in examples.m

@matthijscox
Copy link
Contributor Author

Hi Pier, I haven't been in need for adaptions for GRAMM for a while now, but maybe I found one.

I wanted to show some (binary) sequences in a nice way. For this purpose I hacked some changes into stat_bin2d to allow customized sizing and posititioning, for example:

g.stat_bin2d('size',[0.85 0.6],'shift',[0.5 0.6]);

The shift I essentially only needed to center the squares with the tick labels.
But I do not know if there would have been a better way?

image

P.S. I also created a hack a while ago to remove the axes entirely, but keep the tick labels...

@piermorel
Copy link
Owner

Hi @matthijscox ,

That looks great and pull-request worthy! Do you think there would be a way to compute the shift automatically from the size if there is not other reason for it than alignment?

As for binary sequences, this looks like something potentially related to geom_raster as well, have you looked into it?

@matthijscox
Copy link
Contributor Author

Hi @piermorel,

As far as I understood geom_raster only draws points or lines, I wanted squares with different spacing in x and y. But maybe I misunderstood the function. If I read the equivalent ggplot2 documentation it is what I want, but GRAMM only seems to draw lines:

figure('Position',[100 100 300 300]);
g = gramm('x',1:5,'y',1:5);
g.geom_raster('geom','line');
g.draw();

image

An automated shift would be nice indeed (something like a 'center' option), but I couldn't figure out the math quickly yet from the code. You use the hist2d function, which does some automated positioning. Also I still had to manually update the XLim and YLim with a shift.

I also like the ability to remove the axes, but the function I made now fails when you do manual resizing (it essentially places white axes without tick labels on top of the old ones).

I'm not very happy with the all of this code yet... but if you like I can make a pull request for the size and shift in stat_bin2d to see what you think.

But perhaps I should try to make a geom_tile method, using some of the stat_bin2d patch generation code?
Quick sketch:

  • Use both x and y data input for the center locations of each tile.
  • Add a size option
  • Use color grouping information for the fill color
    The difficulty arises for non-uniformly spaced tiles...

@andreashorn
Copy link

Dear Pierre,

gramm is extremely helpful and great! I've been trying for days to do a simple thing though and now decided to bug you for help. I think it's not possible to do what I want but maybe it is:
I want to create a simple scatter/correlation plot with X and Y variables and only one regression line over the whole data. However, I'd still love to color specific points of the plot differently.

When I run
g=gramm('x',X,'y',Y,'color',groupcolor); g.geom_point(); g.stat_glm('fullrange',1); h=figure('Position',[100 100 550 550]); g.draw();

stat_glm does plot separate lines always and automatically. Any clue how this could work?

Thanks so much! Andy

@piermorel
Copy link
Owner

Hi Andy,

What you are looking for is update(), you can find examples in examples.m, section "Superimposing gramm plots with update(): Using different groups for different stat_ and geom_ methods"

Hope that helps !

@andreashorn
Copy link

Awesome, thanks so much!

@RSKothari
Copy link

RSKothari commented Mar 12, 2019

Hello!
Pierre, I want to start by profusely thanking you for the beautiful package that you've created. It has helped me a lot in the recent months. An added feature bonus would be:

  1. The ability to change legend orientation.
  2. A fix for point alpha (I recommend you suggest everyone to shift to stat_bin2d if they absolutely need point alpha for any purpose).
  3. The ability to draw basic shapes such as circles, rectangles and patches over existing gramm subplots.

This is just a recommendation. I'm sure users can find a work around to the problems I've listed. I love gramm 💯

@ghost
Copy link

ghost commented Jul 25, 2020

Hi!

It seems that some markers are not displayed by geom_points() function. In the code, by default in the parameter 'MarkerEdgeColor' is set to 'none'.

Example case:

x = 1:100;
y = randn(1,100);
g = gramm('x', x, 'y', y);
g.geom_point();
g.set_point_options('markers',{'+'});
g.draw()

but can be made visible by adding a line

set(g.results.geom_point_handle,'MarkerEdgeColor','k')

Could the function display also those markers and set their color automatically?

Best regards, Jakub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants