Column and row names missing in a bipartite network web visualization using plotweb() in Rstudio - bipartite

When I plot my web, which has column and row names, the lables on the visualisation show up as col1 and row 1 etc.
This is despite the fact that ?plotweb states that the defualt is to show full lables:
high.lablength number of characters of upper labels that should be plotted. If zero no labels are shown, default is NULL which plots the complete labels.
and
low.lablength number of characters of lower labels that should be plotted. If zero no labels are shown, default is NULL which plots the complete labels.
Can anyone point me in the direction of where I might have gone wrong?
This is the code I wrote:
cn_dfWEB_summer <- frame2webs(cn_df_summer, varnames = c("Plant", "Pollinator_order", "WebID", "Weight"), type.out = "array", emptylist = FALSE)
plotweb(cn_dfWEB_summer, empty = FALSE)
When I produce the plot, it looks fine, apart from the fact that none of the edges show their proper names. Only col and row numbers. I cannot find an argument that will fix it.

I had the same problem. I had to transform my data frame to an array of integers to solve it.
spxvisitOK <- as.matrix(sapply(spxvisit, as.integer))
Then add the row names and that's it. (columns names were already loaded on my data)
row.names(spxvisitOK)<-c("Abelia sp",
"Bougainvillea sp",
"Bulbine frutescens")
When I compared the properties of my data frame with the test data (safariland), I realized that the package loaded and saw they were slightly different.
I hope you were able to solve it.

Related

How to Transpose Rows to Columns Towards Left Columns? In Google Sheet

SECOND IMAGE CLICK NUMBER 1 I Want To Transpose Row Value Range A2:A50 To Column CZ2 To BC2. Formula Should Be Given IN CZ2. AND VALUE SHOULD GET IN REVERSE OR LEFT COLUMNS.[First IMAGE Click Number 2] 2. If I Give Transpose (AO2:AO50) In CZ2 it Will go range from CZ2 To EW2. I Want Transpose in Reverse Columns. If I Increase Row Value AO2:AO60 It Should Flow Towards Left From CZ2 To AS2. I Mean Transpose Should work towards Left Side Columns. Its Ok with any other formula If Not Transpose. Hope My Question is Understandable. Someone Help Me Out. Thank You In Advance.
It's not clear why you would want to do this. However, the end goal can be achieved by placing the following formula in cell B2 (not CZ2):
=ArrayFormula(IFERROR(VLOOKUP(COLUMNS(B1:1)-COLUMN(B1:1)+ROW(A2)+1,{ROW(A2:A),A2:A},2,FALSE)))
Try it and you'll see what I mean.
The formula is written to be flexible. So if you add or subtract data from A2:A, the value in A2 will always be in Row 2 of the last column to the right in the sheet; and all other values will work backward from there.
If you always want to start to backward progression in Column CZ and Column CZ is not (or may not always be) your rightmost column, you can use this version:
=ArrayFormula(IFERROR(VLOOKUP(COLUMN(CZ1)-COLUMN(B1:CZ1)+ROW(A2)+1,{ROW(A2:A),A2:A},2,FALSE)))
Just understand that, if you don't have columns at least through Column CZ, this formula will fail to work as expected.
I recommend using the first formula I supplied above, since it will always work, no matter how many columns there are, filling backward as far as to the formula column (B2) as needed.
Understand also that if you have more than 103 rows of data in A2:A, that would be more than could fit between B2 and CZ2; so only the first 103 would be displayed.
ADDENDUM (after reading first two comments below):
The principle is the same if you want to run results from "CZ to BC"; only in this case, you want to limit the results to no more than 50.
Place the following formula in BC2:
=ArrayFormula(IFERROR(VLOOKUP(SEQUENCE(1,50,ROW(A2)+50-1,-1),{ROW(A2:A),A2:A},2,FALSE)))
To reiterate, you cannot run formulas that will fill or columns backward. (Even if the sheet is set to right-to-left font with Column A appearing at the far right, the formula is still filling A-Z according to that setup.) However, if you know that you want a 50-column range reserved and you want the answers to go backward, this can still be achieved by placing the formula in the first of the 50 columns rather than the last, as I have proposed above.

Google Sheets: How to make a stacked/aggregate chart

I have made a bar chart which aggregates my data, but is there any way I can split each bar based on the data it is aggregating - similar to how a stacked bar chart would look?
Here is a bad artists impression (thick blue lines mine). The idea is that it's important to know from looking at the graph if I sold 5 at £1, or 1 at £5.
Ideally this would work even if the price for each item is variable, but that is not essential (eg: if there is a 'hack' with hardcoding Apple = 3, I can live with that.)
I'm also fine inputting helper columns etc, within reason, but I would want to be able to easily continue to add things to the list on the left without having to add new helper columns each time (calculated ones are fine, of course.)
Thanks in advance.
UPDATE: With thanks to Kin Siang below, I ended up implementing a slightly modified version of their solution, which I am posting here for completeness.
I added a very large (but finite) number of helper columns to the right, with a formula in each cell which would look for the nth occurrence of the item in the main list (wrapped in an iferror to make the unused cells blank).
=iferror(index(FILTER($A:$B,$A:$A=$D2),E$1,2))
Theoretically it could run out of space one day, but I have made it suitably large that this should not be an issue. It has the advantage over the other solution that I do not need to sort or otherwise manipulate the input range and can continue trickling in data to the main list and have the chart automatically update.
Yes, it is possible to display the chart in your case, however need some data transpose in order to do so, let me show you the example with dataset
Assuming this is your original data:
First sort the data by alphabet, and enter this formula in new column
=if(G39="",1,if(G40=G39,I39+1,if(G40<>G39,1)))
Next add new column for categorical purpose, by using concatenate function
="Price"&I40
In the transform data for chart purpose, enter this formula to split all price into different row, different column for different product
=sumifs($H$40:$H$47,$G$40:$G$47,$A41,$J$40:$J$47,B$40)
After that i select stack bar chart and ensure the price in under series, in case in 23 will have some problem to set price at series correctly, you can use 33 data create stack bar chart and update the data range again, it will work also
Here is the cute chart you expected, accept if help :)
*When certain fruit has less price record, it is advised to fill in 0, as the data table need in same column (see the orange price 3), although I didnot test if blank

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.

How to delete empty cells and shift up in Google Sheets?

Is there a way to delete empty cells in a given range and shift the column up to the desired display as shown below? Closest I came was
=ARRAYFORMULA({A1:C1; TRANSPOSE(SPLIT(TRANSPOSE(QUERY(A2:C,,999^99)), " "))})
which removes empty cells, but splits the first names and surnames into separate cells, which I have not figured out how to avoid. Pfa a made-up sample of current and desired displays:
Current Display
Desired Display
I'm new at this, but I came up with a bit of a brute force method, which may help you.
={
{(A1:C1)};
{FILTER(A2:A100,A2:A100<>"");indirect("N1:N" & 100-counta(A2:A100))},
{FILTER(B2:B100,B2:B100<>"");indirect("N1:N" & 100-counta(B2:B100))},
{FILTER(C2:C100,C2:C100<>"");indirect("N1:N" & 100-counta(C2:C100))}}
Assuming your data block is in columns A1:C100, this formula filters blank cells from each individual column, and then pads each column with blank cells at the bottom, to make the three arrays equal in length/dimension.
Note that in "100-counta(...", the 100 is the expected maximum length of your data column.
This could be calculated, and must be the same for all three columns.
Note also that the first array is horizontal (ends with a semi-colon), followed by the three columns, stacked beside each other (ends with a comma).
Here is a working example.
https://docs.google.com/spreadsheets/d/1MGaqqGrkmIliuAzEqxPtdEVZXWPN2K5W7jFFM-ZnwgE/edit?usp=sharing
If I missed something you were trying to achieve, let me know.
Also, I'm sure that there is a more elegant way to do this, or one not requiring the use of a block of "reserved" blank cells, but I couldn't think of that at the moment.
Edit: The formula as follows also works. But you need to remember to set the "100" value to be equal to the number of rows in your data block, since we pad the columns with the necessary number of blanks rows, after removing the blank cells in each column.
={
{(A1:C1)};
{FILTER(A2:A,A2:A<>"");indirect("N1:N" & 100-counta(A2:A))},
{FILTER(B2:B,B2:B<>"");indirect("N1:N" & 100-counta(B2:B))},
{FILTER(C2:C,C2:C<>"");indirect("N1:N" & 100-counta(C2:C))}}

Add a vertical line to Google Sheet Line Chart

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.

Resources