Can I set the x-axis pivot on a positive/negative barchart as something other than zero? - bokeh

I'm using a barchart to show performance metrics from Jan to June and 99% is my baseline metric. Anything above 99 is acceptable, shown with a green bar extending right-wards, anything below 99 is deemed unacceptable, shown with a yellow bar extending left-wards.
I made a mock up using positive and negative numbers with zero as the natural pivot point. I was looking in the docs for a way to change this x-axis pivot point and couldn't find any, i.e. make my new pivot point 99. Attached is a visual of what I mean.
Is there any way to manually set the x-axis pivot point?
I know what I'm looking for can be achieved with a stacked bar chart/the use of quads, etc. Just wondering if there's a way to proceed with the original hbar object.
Thanks all.
Update: Eugene Pakhomov's answer did the trick...
p.hbar(left=99, y='months', right='counts', height=0.9, source=source...)

hbar has left argument that's 0 by default. Just set it to 99.

Related

Replicate thinkcell "cutout/breaks" in R chart

I have very sparse data and I want to adjust the chart so that I can show the amount of the positive event rather than it being a speck on the chart next to the negative class.
In thinkcell ( an excel and powerpoint add in), there is a cool feature where you can effectively "hide" a part of the frequency. An example is here.
The squiggly lines are a cut off to change the scale.
The kind of data I am working with
a<-data.frame("Changed"=rep(0,900))
b<-data.frame("Changed"=rep(1,50))
example<-data.frame(Changed=rbind(a,b))
hist(example$Changed)
Any suggestions on how to do this or how to represent this? I guess at worst I could change the limit of the chart and just label it to show the value in the base... but its not that pretty or obvious.
Appreciate any thoughts.
J

heatmap.2 color legend custom bins

Hi there stackoverflow community!
I am a graduate student inquiring for some consultation on an aethetics R problem I am encountering.
The data I am working with is in the form of a VERY large matrix (49x51).
My problem is that my data ranges from very small to very large, with the bulk of my data falling within the "very large" end of the spectrum, so unless I convert my data to log10, the heatmap is rather boring and almost entirely the same color.
The spectrum of my data is totally within the range I am expecting, but I am hoping to display it in a more aesthetic way.
Proposed solution: I think I need to bin my data in a non-uniform way. If you look at the attached image, you will see that their heatmap looks nice and the color key shows the heat spectrum in a non-fixed bin format. I would like to do something like that, however, I am not sure how to declare cutoffs for each bin. I would ideally like to declare the cutoffs.
For example, bin 1 (0-1), bin 2 (2-50), bin 3 (51-5000). As you can see, my bins would not be fixed in equal increments.
I have been using heatmap.2 for this. Thanks so much in advance!
heatmap with color legend in non-uniform bins:
Hey #Punintended and #S Rivero,
I think I have reached the point that my heatmap will only improve marginally. Both of you contributed deeply to this success, so thanks! First, to condense the matrix values as much as possible, I normalized by column. I was then able to assign gradients. This turned out much better than I had hoped. As you can see, most of my data is clustered (check out the density in the key) at very low values, this is okay though, for I am interested in the higher values. I had to use custom color gradients to account for possible instances of colorblind attendees that might look at my poster. Anyways, if you guys have comments or recommendations, they will be much appreciated :). Again, thanks a bunch!
enter image description here

Alignment Error When Using Stacked Bars

I'm using a Stacked bars visualisation on one of my Spotfire pages, but whatever the reason, the bars start to get misaligned with the axis as can be seen on the attached image:
The event Start Time is 125.45, but is been shown after 125.5.
A couple of other images to show it better.
This one, it looks like the value (blue box) is correct (237.7 right before 238).
The green box, which is right on top of the previous, has the same 237.7 value but is after 238. How can that be?
Any idea of how to fix that?
without looking at your entire analysis, it's a bit of a guessing game. my gut tells me that your label expression generating the 125.45 is probably not the same as your X Axis expression, or that your Color By expression is providing you unexpected results. I would look at the preceeding segments on that bar and try to determine why they aren't adding up correctly.
Spotfire wouldn't tell you that the start point is at 140 instead of 125 unless there is some reason to. that it doesn't match the tooltip label is indicative of a different expression.

Irregular scaling of axis in R

I have computed values for several categories for three networks. I'd like to create a bar plot in R to show the differences between these parameters for the networks. So far I plotted this with the barplot R function with the categories on the x-axis, their values on the y-axis and to each category three bars (one for each network).
But now I have one value which is much higher than all the others. Therefore the differences for the rest cannot be seen since they're represented only by a thin line because of that one large bar which almost fills the whole plot.
My idea was now to plot the values on the y-axis on an irregular scale, meaning for example, that one half represents the values from 0 to 300, and the other half from 300 to 3000. Is there any way to do this? Or a good alternative approach to handle this problem? I also thought of plotting the logarithm but unfortunatly I have also negative values.
I would suggest that an irregular scale isn't a good plan - I think it confuses viewers of the chart. Instead, you could use the layout() function to plot three separate barplots in a horizontal layout. Thus, each category could have it's own plot, with it's own scale.
If, however, you still have a single bar at 3000, while everything else is at 300, that won't really help. In that case, you could manually set your y-axis limits with ylim=c(min,max). To keep the bar from stretching off the screen, you can just use simple logic to define anything > 300 as 300, or something similar. Then, put a text point there stating the actual value (using text, maybe with arrow).
With those ideas out there, I would suggest that a graph where one value is 10x the other values might not really be worth presenting, or if it is, the main takeaway from it isn't going to be "how do values 2 and 3 compare to each other", it's going to be "holy moley look how much bigger 1 is than 2 and 3". So, it might not be a big deal if one bar is giant and two are small, as long as you aren't doing all 9 on a single plot (which would screw up other, relevant comparisons). So, if you split them using layout(), then it wouldn't be as big of a deal.

Negative values in pie charts

My application visualizes data using a variety of chart types. Some data visualized by a pie chart includes negative values. Pie charts aren't designed to display negatives.
Excel outputs the absolute value of all values. So, -20 is output in the pie chart as a slice with 20% of the pie's circumference. The only way to tell the number is negative is to reference the legend.
Highcharts, which is the charting engine we use, leaves the positive slices intact, but renders the negatives in a very odd and confusing way (Example on JS Lint). Props to them for trying to render negatives, but our users are confused.
Others have suggested filtering out the negatives altogether, since they don't make sense on a pie chart. This strips data and doesn't wholly represent the data set, so it probably won't work for us.
And, others have suggested using a more appropriate chart type, such as a bar chart.
Any other options for solving this? How have you done it?
Use shades of green for positive values.
Use the absolute value of your negative values to then display different negative values in shades of red.
Recently I thought about the same problem, and made rough sample like this.
Please assume that item B has negative value.
'arc' and 'pie' function of d3.js are very convenient to use.
Working sample is here.
I also added concentric circles, like this.
You could use a donut chart around the pie, using one to represent positive values and the other negative values. The key here being the value that represents 100% is the same for both positive and negative. The result is a visual representation of what is positive, negative, and how positive or negative overall the set is.
http://www.highcharts.com/demo/pie-donut
You could use two donut charts around each other. One represents negative values and the other one positive values (possibly indicate which one is which by using different color gradients, e.g. green/red). The trick is to choose the radius of each donut according to the positive or absolute negative value. If you have an overlap adapt the visualization so that the border between both donuts is exactly at the average of both absolute values.
SO this is what I did in Excel using a Donut Pie Chart:
I have percentage ROI between -8 and positive 8 for 4 items.
I took the sum of these subtracted from one, divided by the number of items, then added it back to itself. This makes everything equal to 1.
Then I made =If commands to sort the numbers to the right and left of the above calculated values for the "Negative side". This provides the ability to make two graphs, one using the left and center positive information, and the other center and left negative information.
So, now each section is given 25% of the cashflow with respect to itself. To the right shows what is using funds, and to the right how much that item is contributing. The graph is set up to show the opposite since its more logical.
Then by removing backgrounds, sizing the charts and rings, and coloring each section still visible or no fill, I was able to make what I wanted to show.
Here's a snip of the excel with the code present. Just replace the =
Hope this helps someone!!
Logic
Chart

Resources