How to have a horizontal filling areaplot in R [closed] - r

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 4 years ago.
Improve this question
Imagine a normal area plot of a continuous function y = f(x), which fills the area below the plotted graph down to the x-axis.
But I have to plot my data transposed. The y-data is now on the horizontal axis and the x-data is now on the vertical axis. I want to have the very same plot as before, just transposed ... so the filling should go left, towards the vertical y-axis.
But I can't find a fitting argument for this in the R documentation of areaplot
Can you help me? Is there a work around?

You can switch the axes just by switching where you use x and y. You can fill the area "under" the curve using polygon. Here is a simple example with the Gaussian distribution.
## Data
x = seq(-3.5,3.5,0.1)
y = dnorm(y)
## Plot
plot(y, x, type="l", xaxs="i", xlim=c(0,0.45))
polygon(y,x, col="gray")

Related

Plotting in R missing indices in x plot [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 4 years ago.
Improve this question
I am drawing a plot in R as follow:
respCSV=read.csv("R1.csv")
respCol=respCSV[["RESP"]]
plot(respCol,type='o')
when it plot the series, the x axis lable are not countinuous, instead of 1,2,3,4,
it is 1,5,10.how to fix that?
If the issue is that the axis labels are too spare, and your x variable is continuous you can make your own. This works on standard calls to plot and sometimes it works on plots based on it, but not always.
plot(x, y, xaxt = 'n') # get rid of the default x-axis
axis(1, at = 1:10, values = 1:10) # put the values you want.
Note that there may be other reasons why your axis labels aren't showing up. If the x-axis isn't continuous, the solution will be different.

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.

Plot with darker color for denser areas and transparent color for less dense areas [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 6 years ago.
Improve this question
How can I make a plot in R with ggplot2 that is darker where there are more points and more transparent where there are less points? I tried making a geom_hex plot with a gradient but it is ignoring alpha values.
set.seed(101)
dd <- data.frame(x=rnorm(3000),y=rnorm(3000))
library(ggplot2); theme_set(theme_bw())
Set alpha on points, natural overlap:
ggplot(dd,aes(x,y))+geom_point(alpha=0.1,size=8)
(made points larger to get overlap)
Or:
ggplot(dd,aes(x,y))+stat_density_2d(geom="raster",
aes(alpha = ..density..), contour = FALSE)+
scale_x_continuous(expand=c(0,0))+
scale_y_continuous(expand=c(0,0))
Still working on geom_hex ... I can't actually figure out how to do this ... aes(alpha=..count..) seems as though it should work based on R ggplot geom_hex alpha transparency , but ??
## fails with ggplot 2.1.0 ... ?
ggplot(dd,aes(x,y))+
geom_hex(aes(alpha=log(..count..)))

Equally spaced out lengths in dendrograms [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
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).

Resources