PHPExcel Chart not reversing the vertical axis - phpexcel

I'm working with PHPExcel in order to export Excel chart with Bar Chart.
I can export the chart with the default layout as this image:
But, I want to make the axis layout at the top of chart and reverse the Y-axis as this image:
How can I do that?

After researching the code I found that it is possible to reverse the axis:
$yAxis = new \PHPExcel_Chart_Axis();
$yAxis->setsetAxisOptionsProperties(
\PHPExcel_Chart_Axis::AXIS_LABELS_NEXT_TO,
null,
null,
\PHPExcel_Properties::ORIENTATION_REVERSED
);
$chart = new \PHPExcel_Chart(
"Chart1",
$titile,
$legend,
$plotArea,
true,
'0',
null,
null,
null, //xAxis parameter if you want to reverse the x axis
$yAxis
);
NOTE: If you set the series direction to columns instead of bars
$series = new \PHPExcel_Chart_DataSeries(....);
$series->setPlotDirection(\PHPExcel_Chart_DataSeries::DIRECTION_COL);
the axis are reversed, so what you set as options for the Y-axis will be applied to the X-axis and the opposite.
However reversing the axis cannot be achieved by other methods expected to work:
$chart->getChartAxisY()->setAxisOrientation(\PHPExcel_Properties::ORIENTATION_REVERSED);
or
$yAxis = new \PHPExcel_Chart_Axis();
$yAxis->setAxisOrientation(\PHPExcel_Properties::ORIENTATION_REVERSED);
$chart = new \PHPExcel_Chart(
"Chart1",
$titile,
$legend,
$plotArea,
true,
'0',
null,
null,
null, //xAxis parameter if you want to reverse the x axis
$yAxis
);

Related

Draw() in complexheatmap changes the order of row annotations

I am trying to add row annotations to my heatmap using complex heatmap.
s=Heatmap(total_df,
cluster_columns = FALSE,
column_split = factor(col_split$chr,levels = orderss),
column_order = row.names(col_split),
show_column_names = FALSE,
)
and my annotation heatmap is
anno=Heatmap(order_df[,'type'],name='type' ,
width = unit(1, "cm"),col=colors)
If i draw my annotation heatmap, it returns correct order
but when i try to combine it with primary heatmap using draw(), it changes the entire order.
draw(s+anno)
It would be great if anybody has an idea what is causing this. Thank you very much in advance. :)

How can i specify the color of a bar in a bar chart by its value?

Well, i created a bar chart and now i want to specify the color of a bar depending of its value on y-axis. simplified- if the value is positive the bar should be red and is the value nagative the bar should be blue.
For me it's only possible to change the color along the x-axis but not the y-axis.
from bokeh.palettes import plasma
source = ColumnDataSource(data={'date' : pd.to_datetime(df_data['date'], format='%Y-%m'), 'values' : df_data['values'], 'color' : plasma(256)})
p = figure(x_axis_label='time',
x_axis_type='datetime',
y_axis_label='diff',
tools = [hover]
toolbar_location=None
title="title")
p.vbar(x = 'date',top = 'values', source=source, width=timedelta(days=20), color = 'color')
I've found an example on:
https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html
But i need to differentiate or to color the bars by their values no by their number. I know my example makes no sense, but i only want to demonstrate what my expectations are.
Ok, i found a solution by myself by unsing the cut function of pandas.
import pandas as pd
import numpy as np
values = array(df_data['values']).values)
bins = [np.NINF, 0, np.inf]
categories = pd.cut(values, bins, right=False)
palette = ['blue', 'red']
colors = []
for i in categories.codes:
colors.append[palette[i]]
# Now i can add this column to my ColumnDataSource:
source = ColumnDataSource(data={'date' : pd.to_datetime(df_data['date'], format='%Y-%m'), 'values' : df_data['values'], 'color' : colors}
p.vbar(x = 'date',top = 'values', source=source, width=timedelta(days=20), color = 'colors')
Of course this is just as "quick and dirty" solution and there is enough room for optimization.

Is it possible to find rows of data that are selected by a non-rectangular brush in R shiny?

With R shiny, it is possible to select points in a scatter plot using a rectangular brush and to find their corresponding rows with the function :
brushedPoints(df, brush, xvar = NULL, yvar = NULL, panelvar1 = NULL, panelvar2 = NULL, allRows = FALSE)
a demo can be found here
I would like to select points and find their corresponding rows by drawing a free hand polygon. Is it possible ?
Many thanks for your help !

Legend outside plot does not work with plotyy in Octave

I am trying to create a plot in Octave (using v4.4.1 on Windows) using plotyy and putting the legend outside the plot (because the data covers all the usable space inside the graph). The following MVCE should reproduce the issue fairly well:
% Generate some random data to reproduce the issue
data = rand(1000,10);
data(:,1:8) = data(:,1:8)-0.5;
data(:,9:10) = data(:,9:10)+30;
timedate = linspace(737310,737313,size(data,1));
data_labels={'1';'2';'3';'4';'5';'6';'7';'8';'9';'10'};
% Plot the data
figure('Name','MVCE','Position',[300 200 1000 600])
[ax,h1,h2] = plotyy(timedate,data(:,1:8),timedate,data(:,9:10));
set(h2,'Visible','on');
datetick(ax(1),'x','HH:MM:SS')
datetick(ax(2),'x','HH:MM:SS')
ylim(ax(1),[-1 1])
ylim(ax(2),[20 50])
xlabel('Date & time')
ylabel(ax(1),'Something')
ylabel(ax(2),'Something else')
title('plotyy graph with legend problem')
[hl,hlo] = legend([h1;h2],data_labels,'location','eastoutside');
grid on
This the output of the code using the gnuplot graphics toolkit:
As you can see, the legend does not go outside the plot, and the second y axis is not visible (it looks like part of the plot is actually truncated).
I have tried using the qt and fltk graphics toolkits, which give issues of their own:
With qt graphics toolkit
With fltk graphics toolkit
Can anoybody suggest a fix or at least workaround? Does the same issue also happen in MATLAB or is it Octave-specific?
EDIT
Using the suggestion in Tasos' answer, I managed to almost make it work with gnuplot:
% Plot the data
figure('Name','MVCE','Position',[300 200 1000 600])
[ax,h1,h2] = plotyy(timedate,data(:,1:8),timedate,data(:,9:10));
set(h2,'Visible','on');
datetick(ax(1),'x','HH:MM:SS')
datetick(ax(2),'x','HH:MM:SS')
ylim(ax(1),[-1 1])
ylim(ax(2),[20 50])
ax1Pos = get(ax(1), 'position');
ax2Pos = get(ax(2), 'position');
ax1Pos(3) = ax1Pos(3) * 0.73;
ax2Pos(3) = ax2Pos(3) * 0.73;
set(ax(1), 'position', ax2Pos);
set(ax(2), 'position', ax2Pos);
xlabel('Date & time')
ylabel(ax(1),'Something')
ylabel(ax(2),'Something else')
title('plotyy graph with legend problem')
[hl,hlo] = legend([h1;h2],data_labels,'location','eastoutside');
pos = get(hl,'Position');
pos(1) = 0.9;
set(hl,'Position',pos)
grid on
Which produces:
Apart from the fact that the legend overlays with the second y axis label (which it doesn't on my screen, only when printing to jpg), the problem is that Octave appears to plot two legends on top of each other for some reason: one with the first set of data attached to the first set of axes, and one with the complete set of data, for both axes right on top of the first legend. This is obviously wrong, and trying to set the Visible property of hl to off deletes both legends, not just the one.
UPDATED: deals with both legend placement and OpenGL precision affecting graph.
Regarding the problem of the legend not appearing exactly in the position you want it to, you can manually adjust the position of all axes involved in a figure, to place them exactly where you want.
Regarding the problem of OpenGL being unable to deal with the precision involved when adding small numbers to a large number, plot the graph with only the small numbers involved, and then simply adjust the xticklabels to correspond to the numbers you desire.
Full code below:
% Generate some random data to reproduce the issue
data = rand(1000,10);
data(:,1:8) = data(:,1:8)-0.5;
data(:,9:10) = data(:,9:10)+30;
t_offset = 737310;
timedate = linspace(0,3,size(data,1));
data_labels={'1';'2';'3';'4';'5';'6';'7';'8';'9';'10'};
% Plot the data
figure('Name','MVCE','Position',[300 200 1000 600])
[ax,h1,h2] = plotyy(timedate,data(:,1:8),timedate,data(:,9:10));
set(h2,'Visible','on');
ylim(ax(1),[-1 1])
ylim(ax(2),[20 50])
ylabel(ax(1),'Something')
ylabel(ax(2),'Something else')
title('plotyy graph with legend problem')
[hl,hlo] = legend([h1;h2],data_labels,'location','eastoutside');
set(hl, 'position', get(hl, 'position') .* [0.975, 1, 0.975, 1] )
grid on
ax1Pos = get(ax(1), 'position'); ax2Pos = get(ax(2), 'position');
ax1Pos(3) = ax1Pos(3) * 0.95; ax2Pos(3) = ax2Pos(3) * 0.95;
set(ax(1), 'position', ax2Pos); set(ax(2), 'position', ax2Pos);
XTicks = get(ax(1), 'xtick');
set(ax(1), 'xticklabel', datestr(XTicks + t_offset, 'HH:MM:SS'))
xlabel('Date & time')
set(ax(2), 'xtick', []);
Output:

rchart nvd3 - set tickmark interval

I'd like to specify the interval on the xAxis of a lineChart in rchart nvd3 to be 1.
Currently I have a dynamic chart that has the xAxis being either 0-6, 0-5, or 0-3 - when xAxis only ranges from 0-3, the tickmark interval automatically becomes 0.5, but in this case doesn't make sense, and I would like it to still go by integer intervals - how do I specify that?
Currently my code looks like:
p <- nPlot( yvalue ~ xvalue, data = dat, group = "scenario_id", type = "lineChart" )
p$yAxis(tickFormat = "#!
function(d) {return d3.format('%')(d)}
!#" )
You could try to manually set the tick values by doing:
p$xAxis(tickValues=min(dat$xvalue):max(dat$xvalue))

Resources