Add a vertical line to Google Sheet Line Chart - google-sheets

I have a sheet with a line chart, now I'm trying to do something maybe very simple: I would like to add to this chart a vertical line using a value in a cell.
So I have this line chart
And a cell with the date 2016/01/01, I would like to have a vertical line through all the chart on the cell date
I can't figure out how to do it...
This is a copy of that sheet: https://docs.google.com/spreadsheets/d/1oeiwmeDT8pUVqBQvoE_cqk7mZxxvD5moZr41Vp4IN2I/edit?usp=sharing
I would like to show a vertical line using the "Purchase date"

I had the same problem and created a solution to overcome limitations of Google Sheets charts.
The main idea is to create an additional line in the chart, with only two points, both with the desired date. The value of the first point is 0 and the last has the maximum value of the Y axis. This way, the line always covers the entire height of the chart.
Screenshot of the Chart
Note that it is necessary to add two new values in the X axis (highlighted in blue on the sheet). Don't worry with the fact they are repeated. Google Sheets handles it correctly.
These values can be placed at the beginning of the lists. This way, it is possible to add new values at the end of them.
This solution can be viewed in: "[GoogleSheets] Dinamic Vertical Line in a Chart"
To change position of red line, just select a different value in "Purchase date" (yellow cell).
I made a merge of my first solution with the one suggested by dimo414 and created a new solution with two variations.
In the previous version of the spreadsheet, there were only two points to draw the vertical line.
In the new version, a third point were inserted to show intersection between the line and the real curve. A new column was also created, containing only a label for the new point.
The result is:
Theses changes can be seen in green background in sheets 'Dashboard_v2' and 'Dashboard_v3' of the SpreadSheet.
To determine coordinates of the new point, two approaches were used:
Search Purchase Date directly in the dataset (see sheet 'Dashboard_v2')
If the goal is to highlight only points of intersection that belong to the original dataset, it is just necessary to VLOOKUP() the date in the dataset.
Interpolate the two points immediately smaller and larger than the purchase date (see sheet 'Dashboard_v3')
Given the points [x1,y1], [x2,y2] and a value of x (where x1 <= x <= x2), its possible to find an interpolation point [x,y] with the following formula:
y=(y2-y1)*(x-x1)/(x2-x1)+y1
Although this formula is easy to implement, find the correct points to interpolate is more challenging and requires a bit of creativity.
At first, I thought of using a JS script to make things easier, but decided to use only builtin functions.
By the way, different approaches to find [x1,y1] and [x2,y2] are welcome.
To make things easier to understand, each point coordinate is determined in a different cell (see L2:M5) and the point of intersection is in L6:M7.
Of course, its possible to join all of them in just one cell, but I thought it would be harder to understand.
To close, one more detail: According to above definition, interpolation formula is valid only if (x1 <= x <= x2). Thus, both cells C2 and M6 have protections to limit the value of 'x'.

One way is to add a label to your x-axis.
For example, this is a chart that plots weight against date, with a label "Cheat Day" on 2021-07-21
For the data:
Date
Label
Weight (kg)
Weight Goal (kg)
2021-07-19
83.85
75
2021-07-20
84.55
75
2021-07-21
Cheat Day
83.8
75
2021-07-22
84.95
75
2021-07-23
83.75
75
Go to Edit the chart > Setup > Under X-axis > Click on ••• next to your "Date" column > Add labels > Select the column "Label" as your label.
Your Chart Editor > Setup should look like this:

you can have it like this, unfortunately not programmatically. the only way is to insert a line via Drawing and position it manually where needed.
spreadsheet demo

As best I can tell there isn't a way to add a vertical marker line to a chart in Google Sheets. One option that may be "good enough" in many cases is to "Add notes to a data point" and then use "Format data point" to make the point more visible. Here's an example, from your spreadsheet:
Unfortunately one limitation with this approach is you can only label a data point in the data set the chart is displaying. In your case the date you wanted to mark with a line isn't in the data set, so this won't work directly. You might be able to introduce a separate data series consisting of just that date and then add a note to that data point, but I haven't fiddled with it enough to make it work.

Related

Tableau: Subset multiple time dependent histograms into multiple rows and columns to fit the screen

I am trying to replicate the plot below (done with ggplot in R) using Tableau:
However, I can't see how I can subset the plot so it fits the screen using Tableau. Using Tableau, this is what I get:
I've attempted adding the following but it stops plotting the histograms and ends up messier:
Row Divider (Discrete):
INT((INDEX()-1)/(ROUND(SQRT(SIZE()))))
Columns Divider (Discrete):
(INDEX()-1)%(ROUND(SQRT(SIZE())))
How can I achieve the plot in R using Tableau?
P.S.: The datasets are different in case you were wondering why Monday doesn't look the same.
You're on the right path using Row-Column divider, but you need to go some step further using the small multiple technique.
For instance, you need to move WEEKDAY in the detail mark and then, use column and row divider in column and row shelf.
Doing so, you'll also need to right-click on CNT/Ride Id Hash) and compute it with WEEKDAY.
Here's a cool guide by a Tableau Zen master showing how to work with this tecnique: https://www.vizwiz.com/2016/03/tableau-tip-tuesday-how-to-create-small.html

How to create a histogram in Google Sheets with a log scale on x-axis

I need to create a histogram on Google Sheets, and I need it to have a log scale on the x-axis. This is because there are some random high numbers on my column, most numbers are clustered at the beginning.
The option shows up for the y-axis, but not for the x-axis. I think that when I was trying different options it showed up for a time...???? But now it just disappeared.
Please help!
Try normal chart (bar or line) and building a histogram table manually
Use FREQUENCY() formula for this. This way you can make your own classes the way you like and you can then make whatever chart you like.
Take a look at my solution - line chart with logarythmic y-scale.
X-scale as I see is unavailable for manipulation, but you can use own values and treat them as text.
Example dataset: 100 random values from 0 to 35.
Classes are powers of 2 (increase by 1/2 with each step)
Here is my example file. See if it helps
https://docs.google.com/spreadsheets/d/13xVVwhUrMcDj-ec7xpTJv-8cDjlh8zXT46zrqVVLnk0/copy

Google Sheets: Swap X and Y Axis in Chart

I am trying to illustrate the twist in a sail using a chart, showing the effect of various twist amounts.
However, try as I might, I cannot swap the x and y axis! The cells B3:B8 are the height going up the sail, where the measurements were taken, and should be the y-axis.
The columns C:V are series, which are different sets of measurements taken at the various heights up the sail, with the degree of twist as the series' values. This is what I have:
I've also tried to create the chart from Transpose()d data (swapped rows <-> cols) but ended up with the same chart! The "Height" is supposed to be the Y-axis, and the values ("Degrees") the X-axis.
I must be missing something obvious, but Google is not my friend today. I have created a sample Spreadsheet here if anyone can help. MTIA.
Currently it is not possible to define the Y-Axis to a specific range for Smooth Line Chart, in fact, the only way this can be defined is by using Bar Chart.
As a workaround, you can use Bar Chart to define the Y-Axis like this:
Please note that it only looks best when displaying one or two series, the bars would look squished when more series are added.
As for the original intention of defining Y-axis for Line Charts, or a completely new type of chart, you can file a feature idea request here:
How To Submit a Feature Idea Request
Google Workspace Feature Idea Request Link

Counting the Number of Empty Cells between Non-Empty Cells in Google Sheets

I'm trying to count the number of empty cells that exist in a column between each non-empty cell but haven't been able to work out how.
Using this, I'm also trying to find the largest "empty distances" and locate the cell in the center of these distances.
The sheet I'm working with lists a set of marker colors and denotes the ones that are owned out of the full set of colors. I'm trying to find the largest ranges of missing colors and then find the colors in the middle of those ranges in order to find a handful of markers that would best help to fill out the spectrum.
Columns 1-6 are information- Column 7 marks whether the color is owned:
I may have an answer that helps you.
I could only get it to work using a helper column, but someone may know how to eliminate that requirement.
The helper column creates an array, basically listing the row numbers of the rows that have an "x" in your column B.
The main formula then measures the gap between each of these listed row numbers. It also checks the gap before the first "x", and after the last "x". Note that I have the data starting on row 2, which complicates the formula, but makes the sample sheet clearer - this can easily be changed to row 1 if you prefer.
={F2-1;
query(ArrayFormula(if(isnumber(F3:F),F3:F-F2:F-1,"")),
"select Col1 where Col1 > 0",0);
counta(A2:A)-indirect("F"&COUNTA(F$2:F))}
See a sample sheet here:
https://docs.google.com/spreadsheets/d/19QUFGRqTT6BqOsBrEBpTIxQCeNdRa5mzXhxQpCZ8sV4/edit?usp=sharing
Then I used a second formula to calculate the max gap between "x"s, (or before the first or after the last x).
Note that calculating the midpoint of the gaps, and doing a lookup of the corresponding mid-point colour, is something that can be added to this answer, if you share a sample copy of your sheet and share it for editing.
Let me know if this helps. I'll add more explanation to describe what the formula is doing tomorrow.
And I'll provide a second tab with the formulas adjusted to work with data beginning on row 1.
You can also get the lengths of the gaps using Frequency:
=ArrayFormula(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),if((B1:B20="X")*(A1:A20<>""),row(B1:B20))))
but finding the centres of the gaps and allowing for equal-sized gaps is more difficult.
This should find the position of the "X" at the end of the longest gap:
=ArrayFormula(
sum(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20)))*(sequence(countif(B1:B20,"X")+1,1)<=
match(max(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20)))),frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20))),0)))+
countif(sequence(countif(B1:B20,"X")+1,1),"<="&
match(max(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20)))),frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20))),0))
)
and then it should just be a case of working backwards from there to the centre of the longest gap. However the formula needs further refinement to deal with the cases
(1) Where the longest gap is after the last "X"
(2) Where there is a tie for the longest gap
(3) Where there is a need to list the longest, second longest, third longest gap etc.

Google Sheets - Waterfall Chart Subtotal Labels

Here's a data sample
and screenshots too.
I'm trying to make a waterfall chart with Start/End year performance and contributions. I was trying to make the chart more descriptive by including a customized label, with percentage variations.
No matter how I select the labels column, the ending Subtotal bar is independent from the others. I'm trying to customize both bottom and top labels, but I'm more concerned on the top one (the growth/loss percentage or the absolute value at the end of the year.
Thanks again to #kirkg13 for guiding me through the solution. It was not quite difficult in the end, but I think the option should be made clearer/simpler in some future updates.
You can check my solution on the Chart 4 from the sample file as long as It'll be online. Steps are as follows:
1: Lay the data in three columns: Column names, values (start value, absolute deltas and end values) and custom labels (whatever you like, in my case % variations for all columns except start/end). Include the subtotal column
2: On the chart editor make sure all the data is selected, including the sub-total (from Start Year to End Year in my example). Check that x-axis and series are correctly assigned (column 1 and 2); from the series click and add a label, selecting the third column.
3: This is the part I had difficulties finding: on customize>series>data labels, you need to:
Uncheck the "Add subtotal..." box (optionally check the "Use first value as subtotal" one, for better color clarity
Below, click "Add new subtotal".
The new Subtotal must be of "type" "Replacing" and "column index" as the last column you have
The end result is as below: all columns have a customizable name and label, with coherent colors.

Resources