How to plot a large number of vbar in a Bokeh figure - bokeh

Hi I am trying to modify the example code here
https://docs.bokeh.org/en/latest/docs/gallery/bar_mixed.html
I removed the toolbar_location=None so that the Bokeh toolbar can show, also I made factors array very large.
I would like to see a figure that I can pan/scroll to view more data rather than it is doing right now-congested all the bars in the fixed width.
How to do that?

As of version 0.12.16 Bokeh only supports initially showing all the factors. There is no mechanism to show only some subset. You can open a GitHub issue if you would like to discuss adding this as a feature.

Related

Plotly Multi Column Horizontal Legend

I am trying to create horizontal bar chart in in R using the plotly package. Due to the length of the legend items I would like for them to show horizontally at the top or bottom of the visual in 2 columns. Is it possible to dictate the number of columns for the legend?
I've been able to place the legend below the x axis successfully using Layout(legend = list(orientation='h')) however regardless of where I put the legend (using the x and y arguments) it is always just one long list. I've seen a github project for creating a multi column legend in js but not r.
Thanks,
This is not possible in a normal way. I think it has its own logic that determines how many place there it is and how many columns it will display then.
So I guess if you make your plot width smaller you could reach the goal that it will just display 2 column.
Also you can try to play around with the margin attribute (https://plot.ly/r/reference/#layout-margin) by setting r and l to 10 e.g.
An other idea could be to make the font-size in legend (https://plot.ly/r/reference/#layout-legend-font-size) bigger, so that it just uses two columns. Hope it helps.
I read the same github page and I thought that it is not possible, but seems to be! I only checked in Python, but I hope this will help in your endeavors in R as well as everyone in Python looking for information. Sadly, there is not a lot of information on Plotly here compared to other packages.
This solved my problem
Setting orientation='h' is not enough. You also have to put the legend items in different legendgroups, if you want them in different columns. Here is an example with legend labels:
fig = go.Figure([
go.Scatter(x=best_neurons_df['Test Size'],
y=best_neurons_df['Training Accuracy Max'],
# You can write anything as the group name, as long as it's different.
legendgroup="group2",
name='Training',
mode='markers',
go.Scatter(x=best_neurons_df['Test Size'],
y=best_neurons_df['Validation Accuracy Max'],
# You can write anything as the group name, as long as it's different.
legendgroup="group1",
layout=dict(title='Best Model Dependency on Validation Split',
xaxis=dict(title='Validation Set proportion'),
yaxis=dict(title='Accuracy'),
margin=dict(b=100, t=100, l=0, r=0),
legend=dict(x=1, y=1.01,xanchor='right', yanchor='bottom',
title='',
orientation='h', # Remember this as well.
bordercolor='black',
borderwidth=1
))
Example image

How to make interactive Bokeh Histograms?

I have been working with bokeh for a little while now and when showing people data they really seem to love being able to interact with the data. I've managed to acheive this via bokeh serve, but only for scatter diagrams. Can this be done with histograms?
The problem, I think, is that as a high-level chart, Histogram() won't take a ColumnDataSource as its argument, which seems to be what the interactivity is based around. I'm not very clued up about this, so any help or comment on workarounds is appreciated.
I fairly new to Bokeh as well - so there may be a better way, but my quick work around was to create my histogram with multiple rectangle glyphs. The only catch is that rect uses the y value passed to it as the center of the glyph, rather than its absolute height.
Something like:
plot.rect(x, y=bar_height/2, width = 1, height = bar_height, source= source_data)
Works for me.

Why does the NVD3 StreamGraph shift the y zero axis over time?

Link to sample image with tilting graph:
Link to NVD3 Streamgraph page:
The nvd3 streamgraph will descend or ascend sharply over time. I searched SO and the NVD3 documentation but didn't find a variable that controls where the zero of the y axis is at each point in time. Nor have I found discussions of this. In other words what makes the whole graph tilt in one direction or the other and how to control or turnoff this tilt.
I read a bit of the initial paper on streamgraphs by Byron but couldn't figure it out and thought I'd ask here.
Could someone please point me towards documentation on this or otherwise provide insight?
The NVD3 code for the stacked area chart accepts four possibilities for the chart style: stack, stream, stream-center, and expand. The default stream graph is the "stream" style, and this is the version that gets off-centre if you have any zero values in your data.
If you set the style explicitly to "stream-center", the chart behaves as expected. However, the radio buttons that switch between display styles switch back to the problematic algorithm, so they will need to be disabled.
chart.style('stream-center')
.showControls(false);
It's possible that the existence of this other display algorithm means that the NVD3 folks are working on it. The github issue page might be a good place to look for updates or responses from them:
https://github.com/novus/nvd3/issues/416

scaling Venn diagram in R

I am trying to plot the Venn Diagram of intersection of 3 sets with the following function:
library(VennDiagram)
draw.triple.venn(10,5,4,2,3,1,1,ind=TRUE,scaled=TRUE).
In the Quartz window I receive 3 identical circles (all of the same size). Where did the scaling go? After several hours of trying, I am wondering if it is a bug or if maybe the previous settings of my plotting area are not allowing it ( i closed and reopened the Quartz window several times). The output value is:
(polygon[GRID.polygon.1498], polygon[GRID.polygon.1499], polygon[GRID.polygon.1500], polygon[GRID.polygon.1501], polygon[GRID.polygon.1502], polygon[GRID.polygon.1503], text[GRID.text.1504], text[GRID.text.1505], text[GRID.text.1506], text[GRID.text.1507], text[GRID.text.1508], text[GRID.text.1509], text[GRID.text.1510], text[GRID.text.1511], text[GRID.text.1512])
Any help or tip would be appreciated. All the examples I see online are depicted already scaled.
According to the manual, scaling only happens for some configurations. One example would be
draw.triple.venn(1,2,3,0,0,0,0)
On the other hand, looking at the source code of that function, there appears to be no relevant use of that parameter at all. And indeed, passing scale=FALSE to the above command still results in scaled circles.
So it looks like with the current source code, you have no control over scaling, one way or the other.
The scale parameter is being ignored in many cases.
Here is another example that is also not plotted to scale
venn.plot <- draw.triple.venn(1883,598,2151,218,221,611,95, c("AL", "RL", "R"),scale=TRUE)
I used this .jar instead:
http://www.cs.kent.ac.uk/people/staff/pjr/EulerVennCircles/EulerVennApplet.html

Can R create a barplot image with clickable bars to insert on a webpage?

I know how to create a barplot, and how to stick it on a webpage; e.g, using hwriteImage in the hwriter package.
What I'd like is for each bar to be a region which highlights on mouseover, and where each bar has a different link when clicked. Similar to this map of the U.S. using the jQuery maphilight plugin, but for a barplot rather than a map. I imagine R could calculate the coordinates of the regions around each bar, generate the HTML AREA tag etc and pass this to maphilight quite easily. Has it been done already? I searched but no luck so far.
Have a look here, which summarises a couple of methods: rggobi and iplots. rggobi looks pretty promising, though maybe the installation looks a bit involved. iplots is only good for scatter plots.
Some other options (I think these are strongest ones at the moment):
googleVis
The googleVis package interfaces with the google charts API: try demo(googleVis) and the third & fourth one are bar chart (there could be more). It has the advantage of being pretty simple to get started with, although these are not R graphics:
df=data.frame(country=c("US", "GB", "BR"), val1=c(10,13,14), val2=c(23,12,32))
Column <- gvisColumnChart(df)
plot(Column)
gridSVG
The gridSVG exports the current grid graphics to an .svg file that can be included into a webpage. Unlike googleVis, it's R graphics (so you can use grid/ggplot2 which are more familiar). It looks like you may have to know some Javascript to further embellish your plots though (e.g. to animate on mouse over, you use grid.garnish(...,onmouseover=...)).
There's some example code you can try here (The really awesome ones are here - usually clicking on the "SVG file" link will have the full interactivity/animation.) (This one is a scatterplot where the points highlight when you move your mouse over them).
As I said - have a look at the package pages, demos, examples, etc to see which suits you.

Resources