Changing whisker length in `geom_boxplot()` and plotly - r-plotly

How do I change the length of the whiskers when working with a geom_boxplot() that I would like to be rendered as a plotly object?
I tried to change the coef argument in the geom_boxplot() function from 1.5 to something wider but that did not work.

Related

Color nodes in Networkx Graph based on specific values

I have looked a bit into the node_color keyword parameter of the nx.draw() method. Here are two different graphs colored using node_colors.
node_colors = [.5,.5,0.,1.]. Colors appear as expected
node_colors = [.9,1.,1.,1.]. Colors do not appear as expected
In the second image, I would expect the color of node 1 to be almost as dark. I assume what is happening is the colormap is getting scaled from the minimum value to the maximum value. For the first example, that's fine, but how can I set the colormap to be scaled from: 0=white, 1=blue every time?
You are correct about the cause of the problem. To fix it, you need to define vmin and vmax.
I believe
nx.draw(G, node_color=[0.9,1.,1.,1.], vmin=0, vmax=1)
will do what you're after (I would need to know what colormap you're using to be sure).
For edges, there are similar parameters: edge_vmin and edge_vmax.

Seaborn boxplots changes (narrows) width of boxes when a hue is chosen, how might I remedy this?

I am using seaborn to create a boxplot. When I specify a column by which to group/color the boxes, the width of the boxes becomes so narrow that they are hard to see. The only change I am making is specifying an argument for hue, which points to a column in the dataframe passed. I have tried using the 'width' parameter (as mentioned here), which does increase the width of the boxplots, but also the distance at which they are spread apart.
Help: How can I maintain the width of the boxes while specifying a hue parameter?
I will show my code and results below:
My dataframe:
Out[3]:
timestamp room_number floor floor_room temperature
0 2016-01-19 09:00:00-05:00 11a06 11 11_11a06 23.0
1 2016-01-19 09:00:00-05:00 east-inner 11 11_east-inner 22.8
2 2016-01-19 09:00:00-05:00 east-window 11 11_east-window 22.9
Use of seaborn with odd boxplot widths, using a grouping factor:
sns.boxplot(x=xunit, y=var, data=df, order=order, hue='floor')
Use of seaborn that has reasonable boxplot widths, but no grouping factor:
sns.boxplot(x=xunit, y=var, data=df)
In version 0.8 (July 2017), the dodge parameter was added
to boxplot, violinplot, and barplot to allow use of hue without changing the position or width of the plot elements, as when the hue varible is not nested within the main categorical variable.
(release notes v0.8.0)
Your code would look like this:
sns.boxplot(x=xunit, y=var, data=df, order=order, hue='floor', dodge=False)
It turns out the the 'hue' parameter causes the issue (I am not sure why). By removing this parameter/argument from the function, the problem goes away, but you must provide extra information so that the boxplots are color coded by the condition desired. The following line of code fixed my problem:
sns.boxplot(x=xunit, y=var, data=df, order=order,palette=df[condition_column].map(palette_dir))
Where palette_dir is a dictionary of colors for each condition, mapped to a column of data.
The boxplots look normal now, but I am struggling to add a figure legend. I am hoping the person who resolved this in this post can point me to their method.

Change legend line style

I am playing with the visual effect of plots, and a question came up while changing the style of a legend.
To be able to save the figure with legends big enough that can be seen usually one needs to change the FontSize property to e.g. 24. When you do that, the size of the font changes, however, the small line next to it has the same size than when it was small. The proportion between line/text seem quite appropriate to me with a FontSize of around 10, while I believe that with big font sizes bigger "eat" visually the line, which is the important part.
Example with fontsize 30 and 10 (please ignore how much I suck in mspaint and the low resolution of the zoomed legend). The proportion between line/text is nicer in the small one.
I was wondering if there is a way to modify that line. I have been checking the properties but I haven't found any relevant one.
NOTE: The LineWidth property does not change the width of the colour lines, but the width of the bounding box.
You could play with the outputs arguments of legend, especially the icons variable (check here).
According to the docs, they correspond to
Objects used to create the legend icons and descriptions, returned as
text, patch, and line object.
Therefore you might use something like this to modify the LineWidth property of any of your plot, or both of course:
clear
clc
close all
x = 1:10;
plot(x,rand(1,10));
hold on;
plot(x,x,'k');
[h,icons,plots,str] = legend('First plot','Second plot','Location','NorthWest');
set(h,'FontSize',30);
set(icons(:),'LineWidth',2); %// Or whatever
Which outputs:
Note that I used R2014a so it might be a bit different for R2014b.

Matlab text() in figure - FontSize property not working

I want to show some text in a plot and adjust the fontsize. In the matlab reference I found it should be something like this:
text(.025,0.6,descr,'FontSize',20);
However, if I do this the fontsize is still the default 10px. I do not get any errors. The following does work:
text(.025,0.6,descr,'Color','red');
And this gives me an error, for unkown property:
text(.025,0.6,descr,'Size',20);
Anyone knows what I am doing wrong? I work on Matlab R2014a on Linux Mint.

MATLAB: latex interpreter font spacing

The font spacing in TeX-typeset equations in MATLAB defaults to being highly compressed. Is there a way to increase the amount of spacing, so that, for example, the numerator and denominator of a fraction do not make contact with the line separating the two?
plot(1:10,rand(1,10));
set(gca,'FontSize',18);
legend('$\frac{xy}{\exp\left(\frac{x}{y}\right)}$');
set(legend(),'interpreter','latex');
I think the easiest way is to use some LaTeX trickery.
Long story short, in LaTeX $ ... $ is used for inline math, but for display math, you should either use \[ ... \] or the legacy way of doing the same $$ ... $$. For LaTeX documents, don't use the latter, but for MATLAB it should be enough.
The difference between inline math and display math, is like the difference between using backticks (``) and indentation in StackOverflow. The first will show your code in-between text, the latter in-between paragraphs. With math, only display mode math will have decent lay-out for larger formulas.
So the following code should fix your problem:
plot(1:10,rand(1,10));
set(gca,'FontSize',18);
legend('$$\frac{xy}{\exp\left(\frac{x}{y}\right)}$$');
set(legend(),'interpreter','latex');
If you want even more, you might want to consult the Not So Short Introduction To LaTeX2e which gets you started with a lot of the tricks of the LaTeX trade.
edit:
What I tend to use as a trick to improve spacing in formulae is using phantoms (\phantom, \vphantom, \hphantom), but \vspace or \vskip might be a little cleaner to use.
Looking through the list of properties for the legend, there doesn't seem to be any way of specifying a line spacing that is consistent with automatic positioning. You can fudge the line spacing by enlarging the box, however, by changing the final entry (height) in the OuterPosition property. It seems the placement of the box is based on its bottom-left corner, so if your legend box is in a North position then you will also need to reduce the second entry (y-position) by an equal amount.
In this example I increase the height of a North-positioned legend box by 25% (which I have found that gives nice results), which increases the line spacing.
h = legend(s1,s2,s3, 'location', 'northeast');
set(h, 'fontsize', 16, 'interpreter', 'latex')
outerposition = get(h, 'OuterPosition');
delta_h = 0.25*outerposition(4);
outerposition(2) = outerposition(2) - delta_h;
outerposition(4) = outerposition(4) + delta_h;
set(h, 'OuterPosition', outerposition)
You have to be wary about resizing the figure after running this code fragment, since changing the OuterPosition property clears the automatic placement of the box with respect to the plot axes. If you resize the figure the legend box will go walkabouts.