Equally spaced out lengths in dendrograms [closed] - r

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
In this diagram, the main information (most nodes) is on the extreme left side.
I want to make the dendrogram easy to read and thus the edges should be proportionally long. Any specific arguments to be used or is it just the data's problem?

Package ape has an option for plotting a tree (or dendrogram) without edge lengths.
library(ape)
# calculate dendrogram from sample data
data(carnivora)
tr <- hclust(dist(carnivora[1:20,6:15]))
# convert dendrogram from class 'hclust' to 'phylo'
tr <- as.phylo(tr)
# plot, use par(mfrow=c(1,3)) to display side by side
plot(tr)
plot(tr, use.edge.length = FALSE)
plot(tr, use.edge.length = FALSE, node.depth = 2)
This calls the plot.phylo function and enables you to manipulate how the dendrogram looks like. To improve legibility of labels, you might need to tinker settings within plot that influence font size (cex = 0.7) or offset of the label (label.offset = 0.5).

Related

How can I plot predicted vs. actual values for a regression tree in R? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am new to R. Since I've done a regression tree and a prediction based on my test data, I wanted to plot the actual vs. predicted values. Which function would you recommend for this? Also, is there a function for the same issue for a random forest?
I tried the basic function "plot", but then I ended up with the regression tree on the y axis and the actual value on the x axis, which was not my intention.
Try the ggplot package rather than the default plot function. Store the actual value and the predicted value in a dataframe and plot it using the ggplot package.
actualAndPredictedData = data.frame(actualValue = testData$y,
predictedValue = predict(rTreeModel,testData))
ggplot(actualAndPredictedData,aes(x = actualValue, y = predictedValue) +
geom_point()

Flatten or Smoothing a Series of Numbers [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
My questions is about smoothing or flattening a series of numbers. I have searched for options, but have not found any. In my sample data set:
dat <- list(-21,-18,-16,-10,-8,-4,-3,-2,-1,-0.9,-0.7,-0.5,-0.3,-0.1,0,0.2,0.4,0.6,0.8,1,2,4,6,9,13,17,20,24)
I would like to logarithmically flatten or smooth the data, possibly to something like this (numbers are rounded to one decimal place):
smooth<-list(-4.6,-4.2,-4,-3.2,-2.8,-2,-1.7,-1.4,-1,-0.9,-0.8,-0.7,-0.5,-0.3,0,0.4,0.6,0.8,0.9,1,1.4,2,2.4,3,3.6,4.1,4.5,4.9)
The above is the square root of the original; however, the signs had to be changed for the negative numbers and it is also not desirable, in my case, that the absolute values of the numbers between 1 and -1 actually increased, instead of decreased. I am able to construct the above, but it is not easy or ideal, and I am wondering if there were simpler and better procedures.
Thank you.
How about something like this:
sign(dat)*log(abs(dat)+1)
plot(dat, col = "red")
points(smooth, col = "green")
points(sign(dat)*log(abs(dat)+1), col = "blue")
legend(x = 1, y = 23, legend = c("original", "smooth", "missuse"),
fill = c("red", "green", "blue"))
with log2:
data:
dat <- c(-21,-18,-16,-10,-8,-4,-3,-2,-1,-0.9,-0.7,-0.5,-0.3,-0.1,0,0.2,
0.4,0.6,0.8,1,2,4,6,9,13,17,20,24)
smooth <- c(4.6,-4.2,-4,-3.2,-2.8,-2,-1.7,-1.4,-1,-0.9,-0.8,-0.7,-0.5,-0.3,0,0.4,0.6,
0.8,0.9,1,1.4,2,2.4,3,3.6,4.1,4.5,4.9)

How to create boxplot with large amount of continuous x-variables and continuous y-variables with R (not ggplot) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How to create boxplot with large amount of continuous x-variables and continuous y-variableswith R
don't use ggplot.
Just like the following figure, the x-axis and y-axis are all continuous numerical variable.
example boxplot
You can plot by boxplot() function. From this tutorial :
https://www.r-bloggers.com/box-plot-with-r-tutorial/
r-blogger is good for your start learning R. Good luck.
You have a multiple options:
http://www.statmethods.net/graphs/boxplot.html
https://www.r-bloggers.com/box-plot-with-r-tutorial/
https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/boxplot.html
https://plot.ly/r/box-plots/
Boxplot between two variables
boxplot(xval~yval)
I would advise a scatterplot though
Now suppose I want to reduce the number of boxplots, I would convert the x axis into some mind of bins using cut
cut divides the range of x into intervals and codes the values in x according to which interval they fall
newyval=cut(yval,20) for 20 bins
then
boxplot(xval~newyval)

ggpairs displaying density functions as unfilled lines [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am hoping to just change the diagonal plots to have simple outlines so I can view the overlap of the density functions more clearly but am not having much luck. Here is the code I have been using:
plot_rh <- ggpairs(data_rh[,1:6], mapping = ggplot2::aes(color = Condition_name),
lower = list(combo = wrap(ggally_facethist, bins = 10)),
diag = list(continuous = wrap("densityDiag"), mapping = ggplot2::aes(fill=Condition_name)))
Plot with filled density functions:
Changing aes(fill=Condition_name) to aes(color=Condition_name) should result in unfilled lines.
You could also change it to aes(fill=Condition_name), alpha = 0.4 to make the filled densities semi-transparent which may improve the view.

R - what is the best way to plot multiple functions $y=cx$ where c is a parameter [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to plot the function y=cx depending on c. It is going to be number of lines going through the point (0,0).
What is the best way to do it?
I mean something like this:
Using abline function seems to be the way. Thanks for the help.
Think this should work. Not sure if it's the best way though
plot(x = 0,y = 0,xlab = "X",ylab = "Y", xlim = c(-10,10), ylim = c(-10,10))
c <- c(1:10) #Store the different values of your constant in this vector
for(i in 1:10){
abline(coef = c(0,c[i]))
}
If you want different limits on your X and Y axis change the values of xlim and ylim.

Resources