R - Creating a fuzzy correspondance analysis - r

I have ecological data of benthic invertebrate species traits. I would like to do a fuzzy correspondance analysis with ade4-package. I have trait sub-categories as columns and benthic sampling places as rows.
I have prepared and plotted a matrix of fuzzy variables with my "painotettu" dataframe using prep.fuzzy.var from ade4-package.
library("ade4", lib.loc="~/Library/R/3.0/library")
w <- prep.fuzzy.var(
painotettu,
c(5, 5, 6, 4, 3, 4, 2, 3, 3,
5, 5, 5, 5, 3, 6, 3, 5, 3)
)
scatter(dudi.fpca(w, scann = FALSE, nf = 3), csub = 2, type = 0, clab.moda = 2)
The result:
The result is very unclear and to sort it out, I have been trying to:
Separate the places into one picture and traits into another
Delete the text boxes so that the names could be seen more easily.
I'm also searching for some function that would compute a matrix that would give numerical values of what the arrows represent.
I'm trying to sort the data to look more like this:
Please let me know if any further clarification is needed.

Related

How to force specific order of the variables in a waffle chart in R?

please do forgive me for potentially asking a really silly question but its really important that the data I am representing in my waffle chart is ordered according to the input of my vector.
I am really struggling to force the graph to not reorder into descending order. Any feedback is welcome.
library(waffle)
x <- c(A = 5, B = 5, C = 2, D = 3)
waffle(x, rows=5)
Obviously the code above is super basic but I am actually learning this from 0 due to the purpose of the code.
Thanks in advance!
If you change the rows = 3, it will be in the right order:
library(waffle)
x <- c(A = 5, B = 5, C = 2, D = 3)
waffle(x, rows = 3)
Created on 2022-08-15 by the reprex package (v2.0.1)

Histogram: 'x' must be numeric

I am currently working on a statical analysis using histogram. However, when I try to plot the histogram of the data, an "x must be numeric" error appeared.
x < - c(1, 2, 3, 4, 5)
y < - c(1, 5, 7, 21, 34)
DATA <- data.frame(x,y)
plot(hist(y ~ x, DATA, breaks = 50))
I try different solutions found on the Stack Overflow community, yet nothing works for my codes. Any help is highly appreciated. Thank You.

What am I doing wrong with dygraph's showZeroValues option?

I'm trying to plot several data series onto the same plot in R, but even with the showZeroValues=TRUE argument in dyLegend(), the legend stops showing values on mouseover when at least one of the series has a y=0 at the current x. I am not sure what I am doing wrong.
Below is a simplified example:
library(dygraphs)
library(xts)
x=data.frame(a=c(1, 2, 3, 1, 0, 0, 2), b=c(2, 3, 1, 0, 1, 4, 5))
x$Date=seq(as.Date("2017-06-01"), (as.Date("2017-06-01")+dim(x)[1]-1), by="days")
d=xts(x, order.by=x$Date)[,1:2]
dygraph(d) %>%
dyOptions(drawGrid=FALSE, fillGraph=TRUE) %>%
dyLegend(labelsSeparateLines=TRUE, showZeroValues=TRUE)
On my computer the dynamic legend skips all x values at which one of the two series has y=0, as can be seen with the cursor being close to zeros but the legend still stuck on the right end of the graph: example.
I had the same issue and found out that it was caused by the xts object containing character strings. The original data frame had a Date column, which I used to create the xts object, but I did not subset the numerical data. This resulted in the xts object being created but with character values (see issue here). Surprisingly enough, the resulting plots were not much impacted, and the output was correct, which made troubleshooting less straightforward.
In your example, the following should solve the issue:
x=data.frame(a=c(1, 2, 3, 1, 0, 0, 2), b=c(2, 3, 1, 0, 1, 4, 5))
x$Date=seq(as.Date("2017-06-01"), (as.Date("2017-06-01")+dim(x)[1]-1), by="days")
d=xts(x[, 1:2], order.by=x$Date) # This is the only change in your code
dygraph(d) %>%
dyOptions(drawGrid=FALSE, fillGraph=TRUE) %>%
dyLegend(labelsSeparateLines=TRUE, showZeroValues=TRUE)

make a figure in R with two panels in the top row and three in the bottom row [duplicate]

This question already has answers here:
Arrange plots in a layout which cannot be achieved by 'par(mfrow ='
(2 answers)
Closed 7 years ago.
I would really like to make a figure in R that has two panels in the top row and three in the bottom row. I would like to pull this off using the base graphics package. I do not want to use ggplot. Thoughts?
plot.mat = matrix(c(1, 1, 1, 2, 2, 2,
3, 3, 4, 4, 5, 5),
nrow = 2, byrow = T)
layout(plot.mat)
layout.show(n = 5)
# looks good
for (i in 1:5) plot(rnorm(10), rnorm(10))
The ?layout help is well-written and has plenty of examples.

How do I Order Boxes on One boxplot graph? (r)

I've read the answers to several questions of this type, so sorry for the repeat, but I had trouble understanding how they applied to how my data is laid out.
What I would like is to order the boxes on my boxplot (which has, say, four boxes) in the order I wish as opposed to alphabetically.
This is a simplified version of my current code:
TotalPer = c(1, 4, 6, 17, 4, 12)
IntPer = c(3, 8, 10, 1, 4, 8)
DomPer = c(4, 5, 10, 20, 13, 12)
IntDomBox <- data.frame(y=c(TotalPer,IntPer,DomPer),
x=c(rep("Total",length(TotalPer)),rep("International",length(IntPer)),
rep("Domestic",length(DomPer))))
with(IntDomBox, boxplot(y~x, main = "Prediction Residuals", ylab="%",
par(cex.axis=0.7)))
This produces a boxplot in alphabetical order. If I prefer to have the boxplot in the order listed in the dataframe (Total, Int, Dom) how would I do this? I know about making it reverse alphabetical instead, but in some cases that is not what I want, so I'd prefer to be able to manually assign the order.
Thanks!
One possibility out of many: Reorder the factor levels before plotting by executing IntDomBox$x <- factor(IntDomBox$x, levels=unique(IntDomBox$x))

Resources