Adding tooltips in Gvis timeline through R - r

I'm looking for a solution in R (if possible) to add a custom tooltip content to a timeline chart built with the googlevis package in R.
Specifically, I have a dataset that looks as follows:
Content1 StartDate EndDate Content2 GroupingVariable GroupingVariable2
I can build the timeline out using the R package using the function gvisTimeline, but I want to know how I can build a custom tooltip for the timeline using the field content2.
The solutions I've seen involve changing the javascript code itself, which I am very unfamiliar with. The reason I am hesistant to do this is that the amount of different content I have would be very timeconsuimg to manually add to the JS code(hundreds of different content) - if I could create the vector in R and use that to populate the tooltip it would be viable.
Further, would it be possible to color the chart based on the a third variable as well?

I figured out a possible way to do this. In the bar label argument of timechart, if I pass an array of strings such as barlabel = c("Content1", "Content2.tooltip") it replaces the tooltip with the custom content. The column must end in the .tooltip for it to work.

Related

Which package to use for displaying custom tables/information in R

Currently I am working on a project to create a Shiny app that displays something similar to the following:
The interactive part of Shiny and the underlying data cleaning code is done. What I need help with is finding a package for customizing the table.
Strictly speaking it is a table, with one observation (the name of which is not included) with 15 variables displayed in a grid pattern. The name of the variable is referenced as "Info x" on the picture and the value is the red x or green check. (In my actual work, each variable has 3 different levels, and they should be displayed with either some custom graphic (that I would also need a package for) or text). In Shiny the output should be a picture, that can also be downloaded (just like a plot).
Try the GT package -->
https://gt.rstudio.com/
or you can use kable --> https://bookdown.org/yihui/rmarkdown-cookbook/kable.html
I have used both, but maybe GT would be better suited for your case

Insert Charts Into Individual Cells

The Issue:
Graphs cant be inserted into cells like images can.
The Request:
The feature "=Image("URL",2)" Should also be available for charts.
You are able to build simple charts within an individual cell using the SPARKLINE function. Here is the documentation.
Here is a simple example:

Bokeh Charts: Custom HoverTool variables for Bar Charts

If I make a bar chart like this:
bar = Bar(data,labels,tools='Hover')
I can make tooltips like this:
hover = bar.select(dict(type=HoverTool))
hover.tooltips = [
('Grade',' $x'),
('Students',' #Students'),
]
However, when I do variables with '#variable' in the tooltips, I am limited to those specified in data. In normal Bokeh plots, I can have custom variables associated with data points by using a ColumnDataSource. Bar does not support ColumnDataSources. Is there another way to make custom variables available in Bokeh chart tooltips (hover)?
There's is an open PR to add this feature to the charts interface.
It's going to be part of the next bokeh release and also be available through the dev builds (or in the master branch of course) as soon as it gets merged if you need it sooner.
I had the same problem. The trick here is to use GlyphRenderer to make the bar chart aware of the data source. For e.g., you can add a line
bar.select(dict(type=GlyphRenderer)) before hover = bar.select(dict(type=HoverTool)). You can then refer your custom variables using #cat, #zero etc. See the following link for more information and a working example.
https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/-aDPTqDPA3M

R - google slider by gwidgets

I am looking for a way to implement sometimes like the slider in googleVis' annotated timeline: https://developers.google.com/chart/interactive/docs/gallery/annotatedtimeline
I can adjust timeframe by both starting and ending points and move the window as well.
gslider only for one slider per track. Would be better to have two or three sliders in one track.
Any suggestions?
The tkexamp function in the TeachingDemos package is one way to create a graph with properties (including data ranges) that can be adjusted using sliders or other GUI tools.

URL for each box in stacked bar graph

I want to create a stacked bar graph as in url below
(source: jpowered.com)
I want to make hyperlink for each of the red ,violet and blue boxes.The graph is possible with jfree chart but i don't know how to make each of the individual bars as URL so that a click on it can refresh the page.
Is it possible to do it with jfree chart?
Does Jquery plot help in this case to make each box url enabled ?Please suggest.
Using jfreechart, you can apply a CategoryURLGenerator to the plot using whichever of the two implementations better suits your needs. The approach is outlined here for the related PieURLGenerator. ChartFactory.createStackedBarChart() uses a StackedBarRenderer and allows PlotOrientation.HORIZONTAL.
Addendum: To generate URLs for individual items, you can examine the ChartEntity returned in a ChartMouseListener, as shown here.
I know that you can achieve something like this in jqPlot without much trouble.
The only think you need to remember, after you create your plot, is to bind your function to jqplotDataClick event. In your function you would need to map your clicks to a structure of urls. I have presented this in a sample example, where only the first series' bars take you to some websites. The sample is on jsfiddle --- it could be found here.
Effectively all comes down to this piece of code:
var urls = ["www.yahoo.com", "www.google.com", "www.java.com", "www.w3schools.com/js/js_obj_date.asp"];
$('#chart').bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
if(seriesIndex === 0){
var url = urls[pointIndex];
window.open("http://"+url);
}
});
EDIT
I do not know an easy way, i.e. that wouldn't involve changing the script of jqPlot, of identifying the clicked bar by highlighting its background. Though I figured out a way to get a similar effect by coloring background of point labels which are on bars, the code would also need to be in the jqplotDataClicked, something like:
var prevClicked;
var prevBackgroundColor;
$('#chart').bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
var str = ".jqplot-point-label.jqplot-series-"+seriesIndex+".jqplot-point-"+pointIndex;
$(str).each(function(){
if(prevClicked)
$(prevClicked).css('background-color', prevBackgroundColor);
prevClicked = this;
prevBackgroundColor = $(prevClicked).css('background-color');
$(prevClicked).css('background-color', 'red');
});
});
You just find the clicked point label using jQuery and apply your style, e.g. changing background color, remembering the previous label so you can remove its color to previous state on click on another bar. First I tried using addClass/removeClass functions but it didn't change a label's style, thus I had to use the css function instead.

Resources