In Excel 2013, I am labeling a scatter plot with values from cells. I'd like the labels to not overlap. I can manually move labels, but I've created a filter to automatically create new plots, so I would like the label deconfliction to happen automatically as well.
Is this possible? Bonus for solutions without VBA.
Example of overlapping labels below:
Here's a non-VBA solution that works if there aren't too many points and the range of values is fairly stable.
It works by splitting your Y series into two separate series, one which has labels above the points and one which has labels below the points.
By default, points will be put into the series with labels below the point. However, for each point, the splitting formula checks whether there is another nearby point that is below or level to the current point. If there is, then the current point is put into the series with labels above the point instead.
I'm assuming you have data in 3 columns: Filter, X, Y. (This also works if you're just filtering on X or Y, you can ignore the Filter column)
Four working columns are required. The first two are X Filtered and Y Filtered.
Using the example in my screenshots below, this formula goes into D2 and fills both D and E columns:
=SUBTOTAL(9,B2)
This just causes the data points to go to 0,0 if they're filtered out, so that they're ignored in the splitting formula.
To make things easier to read, set the names of the filtered values to X (D2:D10) and Y (E2:E10)
Then this formula goes into F2 as an array formula, entered using CTRL + SHIFT + ENTER, and then filled down.
=IF(SUM((ABS(D2-X)<0.75)*(E2-Y>0)*(E2-Y<0.75))+(SUM((ABS(D2-$D$2:D2)<0.75)*($E$2:E2=E2))>1),E2,NA())
This formula creates the series with labels above the point. The formula does two checks:
Checks if there are any other points that are "close" and below the current point.
Checks if there are any previous points that are "close" and level to the current point. (For this check, we can't compare to all points otherwise both points will have labels above the point. We only check up the current point so that the first point still has a label below and subsequent points have a label above.)
If either of these conditions are met, then the value is used, otherwise NA() is used (so that no point is displayed).
In this formula, close is defined as "0.75" on both the X and Y axis. You'll need to change these values in your formula based on what is "close" in your data. I.e. what difference in X and Y values requires labels to be placed on opposite sides of the points.
This formula then goes into G2 to create the series with labels below the point, which is all remaining values:
=IF(ISERROR(F2),E2,NA())
One trick is just required to make the autofilter work on the data. Because we used the SUBTOTAL formula, Excel thinks the last row is a subtotal row and automatically excludes it from the autofilter, even if we select all of the data before applying the autofilter. To use an autofilter, you'll actually need to create an extra dummy row with no subtotal functions before creating the autofilter.
Now, create the scatter plot with 2 series:
Series 1 using X and Y Above
Series 2 using X and Y Below
(No need to include a blank row in these data series)
Format both series to be the same in all details, except Series 1 has labels displayed above points and Series 2 has labels displayed below points.
My screenshots below show results, including when filtering. Labels will always be below values, unless there is another visible point nearby. Each screenshot also shows one of the formulas.
All points:
Filtered on "a"
Filtered on "b"
EDIT: We can actually make the formula a little smarter to handle multiple close level values. This will alternate each subsequent value between having a label above and below. However, it only works while all values are within the "close" range and only if the data is sorted by X first
=IF(SUM((ABS(D2-X)<0.75)*(E2-Y>0)*(E2-Y<0.75))+(MOD(SUM((ABS(D2-$D$2:D2)<0.75)*($E$2:E2=E2)),2)=0),E2,NA())
Related
I am looking for the solution for the following problem. I have a matrix, where a number is filled in whenever the item on the x-axis and y-axis are connected. Since the matrix changes over time, the numbers are not sorted. My goal is to create a line item (on a different tab) whenever a number is entered in the matrix. The line item should contain the number itself and the name of the items on both axes. See example. I fill the first table and want the second table to be automatically generated based on the first table. The numbers don't need to be in ascending order, rather in the order of the first table, going left to right and then down.
I tried a bunch of stuff, using match and index, but it appears not to be working with a matrix.
Example:
To extract the numbers you could use this formula and drag down up to the row that you need:
=IFERROR(SMALL($B$2:$D$4,ROWS($F$2:F2)),"")
On the other hand, to extract the X and Y values you could use two array formulas and drag down as you need it (don't forget to press Ctrl+Shift+Enter in order to works correctly):
X value
=IF(F2<>"",INDEX($A$1:$D$1,MAX(IF(F2=$B$2:$D$4,COLUMN($B$2:$D$4),""))),"")
Y value
=IF(F2<>"",INDEX($A$1:$A$4,MAX(IF(F2=$B$2:$D$4,ROW($B$2:$D$4),""))),"")
The brackets at the beginning and the end of the formula are because are array formulas.
You can find an example here (download it as excel file to test it)
I have a spreadsheet with 1000's points that I want to graph.
Y axis are dates, X axis is time, values are electricity consumption in Kwh.
As you can see updates are in 15min intervals but every other is 0.
a) I want to delete the 0 columns.
b) And graph the result > 255points
excel.jpg
To delete every other column without doing it manually, you can create a formula to help. First insert a row at the top of the sheet (you will delete this row when you are done with it.) Next, in your new helper row, add a MOD function to the first column with the Kwh values (probably column B.) This returns a remainder after we make a division, so we pass the column function to it as our number parameter. The other parameter is the divisor so we will use 2 for that.
=MOD(COLUMN(),2)
With the cell selected, click the bottom right square of the green highlight of that cell (when your cursor turns to a +) and drag it across all of your columns. Now we will have a 0 and 1 in every other column.
We want to convert that formula to values to make sure nothing happens to our data so now copy the highlighted cells and right click to paste special. Here you will change the Paste radio button to Values.
Now we have values in the helper row so we can select all of our columns except the date row, so do that and open the data column. Click the Sort icon and in the sort window now you will click options and choose from left to right. We will then choose to sort by row 1, and choose the order to be smallest to largest.
Now when you click to sort you will have all of your columns with 0 in them (if it was indeed every other column) on the right-hand side, and all of your data is in the left. Easily select all of the zero rows now and delete them manually with one click. Also delete the helper row you created and you have the sheet ready to graph.
Select all of your data including column A and Row 1, and then go to the insert tab. In charts you can see the different types of graphs. Check the recommended charts or experiment by clicking on the different types of graphs to see which one fits your needs the best. If you choose the 2 Line or Scatter for instance, it will graph out each day in different colors showing Kwh on the Y axis, and X will be the time. You can then format as you wish.
I have a chart (scatter with smooth lines and markers) containing six series. The series all share the same X values. On the same sheet, I have one column of X values and six columns of Y values, one for each series (all series share the same X values). The user needs to be able to smooth small irregularities in the Y values. Ideally, the user would simply click a point directly on the chart and drag it up (to increase the Y value) or down (to decrease the Y value). But since that is impossible AFAIK, the second best solution would be for the user to click the point and have VBA select the cell containing the corresponding Y value. My question is: How do I define an event for the point click which I can capture in a VBA handler? The handler can then decode the point information, determine sheet cell, and select it.
I am trying to draw a line graph in Excel 2010. The y column data source has some gaps in it and I want these to be ignored for the graph. Seems to default these to zero. I know the "Hidden and Empty Cell Settings" exists, but this is only giving the option to set it to zero. Any other way to get my graph looking the way I want it
Image available once I have enough reputation!
if the data is the result of a formula, then it will never be empty (even if you set it to ""), as having a formula is not the same as an empty cell
There are 2 methods, depending on how static the data is.
The easiest fix is to clear the cells that return empty strings, but that means you will have to fix things if data changes
the other fix involves a little editing of the formula, so instead of setting it equal to "", you set it equal to NA().
For example, if you have =IF(A1=0,"",B1/A1), you would change that to =IF(A1=0,NA(),B1/A1).
This will create the gaps you desire, and will also reflect updates to the data so you don't have to keep fixing it every time
In Excel 2007 you have the option to show empty cells as gaps, zero or connect data points with a line (I assume it's similar for Excel 2010):
If none of these are optimal and you have a "chunk" of data points (or even single ones) missing, you can group-and-hide them, which will remove them from the chart.
Before hiding:
After hiding:
In the value or values you want to separate, enter the =NA() formula. This will appear that the value is skipped but the preceding and following data points will be joined by the series line.
Enter the data you want to skip in the same location as the original (row or column) but add it as a new series. Add the new series to your chart.
Format the new data point to match the original series format (color, shape, etc.). It will appear as though the data point was just skipped in the original series but will still show on your chart if you want to label it or add a callout.
There are many cases in which gaps are desired in a chart.
I am currently trying to make a plot of flow rate in a heating system vs. the time of day. I have data for two months. I want to plot only vs. the time of day from 00:00 to 23:59, which causes lines to be drawn between 23:59 and 00:01 of the next day which extend across the chart and disturb the otherwise regular daily variation.
Using the NA() formula (in German NV()) causes Excel to ignore the cells, but instead the previous and following points are simply connected, which has the same problem with lines across the chart.
The only solution I have been able to find is to delete the formulas from the cells which should create the gaps.
Using an IF formula with "" as its value for the gaps makes Excel interpret the X-values as string labels (shudder) for the chart instead of numbers (and makes me swear about the people who wrote that requirement).
Not for blanks in the middle of a range, but this works for a complex chart from a start date until infinity (ie no need to adjust the chart's data source each time informatiom is added), without showing any lines for dates that have not yet been entered. As you add dates and data to the spreadsheet, the chart expands. Without it, the chart has a brain hemorrhage.
So, to count a complex range of conditions over an extended period of time but only if the date of the events is not blank :
=IF($B6<>"",(COUNTIF($O6:$O6,Q$5)),"") returns “#N/A” if there is no date in column B.
In other words, "count apples or oranges or whatever in column O (as determined by what is in Q5) but only if column B (the dates) is not blank". By returning “#N/A”, the chart will skip the "blank" rows (blank as in a zero value or rather "#N/A").
From that table of returned values you can make a chart from a date in the past to infinity
I would like to graphically represent how some real valued data has been discretized/binned. I have an array of real numbers ranging from 1 to 35. For each value, I have a corresponding natural number in the range of -2 to 19. I would like to show all of the real numbers on a number line colored based on which natural number corresponds to each one. Is this possible in excel? If not is there something else I can use to accomplish this?
Since you have no y-axis, here's how I would do this: Create an Excel spreadsheet with the numbers 1-35 in Column A, and with the numbers -2 to 19 along the top of Row 1.
In each intersection of the right number with the right color value, enter a 0.
Graph this range, using a line chart with point markers. You will end up with various points along the x-axis, with different colors and shapes, according to the distribution in your table. Now you should completely remove the y-axis (no line, no fill, no labels, no ticks), gridlines, and legend.
Finally, I would edit the various data series, by removing the lines (leaving the markers), and setting all the line markers to use the same shape, with only the colors differing.
You can fudge conditional formatting in Excel charts. Check out the "Conditionally Formatted Line Chart" example in this tutorial:
Conditional Formatting of Excel Charts