How do I specify the columns that should appear in a hover in a `holoviews.operation.gridmatrix`? - holoviews

In the following, the hover simply shows the x and y values for each individual plot. How would I additionally show country in each plot?
from bokeh.sampledata.autompg import autompg
autompg_ds = hv.Dataset(autompg)
hv.operation.gridmatrix(autompg_ds, chart_type=hv.Points).opts(hv.opts.Points(size=2, tools=['hover']))
How do I specify the columns that should appear in a hover in a holoviews.operation.gridmatrix?

Related

Printing text on plot in a specific position Stata

I am trying to print a text in the botton right of some plots. I know that I can use the coordinates to do that in the option text of a plot, but given that I have to plot around 50 charts that change a lot in terms of the axis magnitude, I´m looking if there is a way to do this by default.
clear all
set obs 100
gen x = runiformint(1, 100)
gen y = runiformint(100, 200)
egen z = seq(), f(1) t(100)
scatter x z, text(1 100 "XXXX")
scatter y z, text(1 100 "XXXX")
In this code I can print the text in the first scatter but not in the second one.
Suppose you want to put text in the bottom right-hand corner of plot. Consider using a title option:
sysuse auto, clear
scatter mpg weight, subtitle("frog", pos(5) ring(0))
scatter length weight, subtitle("toad", pos(5) ring(0))
See for discussion https://www.stata-journal.com/article.html?article=gr0051
Warning: Nothing rules out such a title obscuring point, line or area elements that represent data.

Set the amount of visible bars in the initial plot

I have a barplot using the bokeh library, and I would like to show only the first 5 barplot and then if I want to see the rest of the bars I have to move the x axis to the right or left. I am struggling in find the information that would allow me to do so.
An example would be this:
from bokeh.plotting import figure
from bokeh.io import output_file, show
import calendar
values = [2,3,4,5,6,7,8]
days = [calendar.day_name[i-1] for i in range(1,8)]
p = figure(x_range=days,plot_height=500)
p.vbar(x=days, width=0.5, top=values, color = "#ff1200")
output_file('foo.html')
show(p)
and what I would like it would be something like this:
and then if I want to see the resting of the days I have to click on the figure and move the mouse.
Any idea?
I wasn't able to find a solution for limiting the x axis while using categorical data. Instead I made a workaround where the x axis labels are overridden by days of the week. This makes it possible to use x_range to limit the x axis.
#!/usr/bin/python3
from bokeh.plotting import figure
from bokeh.io import output_file, show
values = [2,3,4,5,6,7,8]
days = [0,1,2,3,4,5,6]
p = figure(x_range=(-0.3,4.3),plot_height=500)
p.xaxis.major_label_overrides = {0:'Monday', 1:'Tuesday', 2:'Wednesday', 3:'Thursday', 4:'Friday', 5:'Saturday', 6:'Sunday'}
p.vbar(x=days, width=0.5, top=values, color = "#ff1200")
output_file('foo.html')
show(p)

R: Is it possible to put a text box so many cm/inches above a line in graph? (Whithout changing scale of graph)

Is it possible to put a text box so many cm/inches above a line in graph in R? (Whithout changing scale of graph). So im plotting the image using plot and i want to specify that the text using the function: text() but I always want the text to be 1cm above the arrow at the specified x-coordinate.
enter image description here
You can do this simply with ?text. So not entirely with cm's but if you know the range of your data you can position your text as data points in the plot.
Example:
Let's make some test data.
dat <- matrix(rnorm(3*4), ncol=2)
colnames(dat) <- c("v1", "v2")
Create a scatter plot. You can of course apply text to any graphical plot, but I'm keeping it simple.
plot(v2 ~ v1, data = dat)
And now just create a line, in whatever direction. I'll just go with an abline at height 1.0 on the y-axis
abline(h=1.0)
text(1,1,"this is an abline", pos = 1)
With text I add text on position 1,1 (x, y) in the plot. I adjust it with pos so It doesn't get crossed by the abline.
Good luck!

How to display a calculation on data values in R legend

Here's a fiddle for a simplified version of a plot I am trying to generate.
On line 44 the plot points are sized according to 1/Error:
main_aes = aes(x = Date, y = Popular_Support, size=1/Error)
But instead of displaying 1/Error values in the legend, I want it to display Sample Size which is 1/Error^2, which the legend title being Sample Size.
I only want this displayed in the legend, but I still want the original values to weight the point sizes.
How can I do this? How can I perform a calculation on the legend text that is displayed and change the legend title?
You can do this as follows:
plot + scale_size_continuous(breaks=seq(40,70,10), labels=seq(40,70,10)^2,
name="Sample Size")
Also, plot is an R function, so it's probably better to use a different name for your plot objects.

Change the layout of heatmap.2 figure

We are using heatmap.2 to draw figures. With the default parameters we can get the following layout/outlook (see Figure 1).
How to remove the right row names/row labels, for we have thousands of labels (see Figure 1) ?
Can we draw the Color Key upwards to downwards (see Figure 2) ?
Figure 1
Figure 2
Question 1: The row names can be removed by setting labRow = "".
Question 2: This is not possible without changing the function. heatmap.2 uses a 2 by 2 table for the layout and puts the key in the upper left cell if one is to be added. You would need to edit the function to have a 2 by 3 layout and put the key in the lower right cell, editing the display to show as indicated.
Question 2. Ian gives an excellent explanation for the layout of the heatmap.2 components. You can change the layout (number of cells in a table where each element is "plotted", e.g. 2x2, 2x3, 3x2, 3x3) and the position of each of the elements of the heatmap (i.e. heatmap, row dendrogram, column dendrogram, and key).
For example:
# Define custom layout for heatmap
mylmat = rbind(c(0,3,0),c(2,1,0),c(0,4,0)) # creates 3x3 table with location of heatmap elements defined
mylwid = c(1.5,4,0.5)
mylhei = c(1.5,4,1)
# Plot your heatmap
heatmap.2(matrix.name, lmat=mylmat, lwid=mylwid, lhei=mylhei, ...)
Although you cannot change the key to be vertical versus horizontal (as far as I know!), you can position it anywhere around the heatmap and/or dendrograms.

Resources